KillingSpark / KillingSpark/rustbus
A connection should be interruptable while waiting for new messages
- Dominant language
- Rust
- Stars
- 65
- Forks
- 14
- PR merge metrics
- No merged PRs in 30d
Description
This is useful for graceful shutdown of a service. When e.g. SIGTERM is sent to your service just stopping the process is pretty rough. dbus-daemon seems to handle it well enough but it would be nice to actually close the connection properly. For that the reading should be interruptable.
This could be done by using the good ol' reliable self-pipe trick and using `select()` to wait for data before using a blocking `recvmsg`. This should also provide a way to send a code so the error handling on the reading call-site knows what's what.
The read loop would look something like this:
```rust
loop {
match conn.get_next_message() {
Err(Error::Interrupted(code)) => {/* probably want to return, depending on the user defined code*/}
Err(error) => {/*other error handling*/}
Ok(msg) => {/*message handling*/}
}
}
```
When creating a conn, a second (cloneable) struct should be generated, that allows to interrupt reads on the conn at any time.
This will contain a `Rc` for the write end of the self-pipe. All it would do is writing the code to the pipe.
`FdWrapper` will close the contained `RawFd` on drop.
```rust
const INTR_SHUTDOWN: u8 = 0xFF;
conn_interrupter.interrupt_read(INTR_SHUTDOWN).expect("Can't even send interrupts to the conn anymore :((");
```
Contributor guide
No contributing guide indexed for this repository
Research direction
Start by locating the connection implementation and the conn.get_next_message() read loop; the issue does not name files or tests. Review how recvmsg and existing errors are handled, then assess the proposed FdWrapper and interrupt_read entry points. Done means a cloneable interrupter can stop a blocked read and deliver the caller's code through the documented error path.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- networking
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100