Eugeny / russh

Rust SSH client & server library
https://docs.rs/russh
964 stars 112 forks source link

Handle client disconnections #373

Closed EpicEric closed 1 week ago

EpicEric commented 1 week ago

Currently, there's only handling for sessions errors - and even in this case, there's no way to refer to the handler itself, only to the error. In cases like the library-provided examples echoserver and ratatui_*, this leads to leaks in the form of Arc<Mutex<HashMap<...>>> entries, which is troublesome for any real application.

From what I've managed to hunt in the source code so far, it only seems to log the disconnection without doing much else. Ideally, there should be a client_disconnected callback that takes the Server::Handler instance in order to handle cleanup, for example.

Patryk27 commented 1 week ago

fwiw, I'm using impl Drop to know when a client disconnects and it seems to work pretty reliably.

Eugeny commented 1 week ago

Correct - simply do your cleanup in drop() as the handler gets dropped when the session is closed.