Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle client disconnections #373

Closed
EpicEric opened this issue Nov 12, 2024 · 2 comments
Closed

Handle client disconnections #373

EpicEric opened this issue Nov 12, 2024 · 2 comments

Comments

@EpicEric
Copy link
Contributor

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
Copy link

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

@Eugeny
Copy link
Owner

Eugeny commented Nov 13, 2024

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

@Eugeny Eugeny closed this as not planned Won't fix, can't repro, duplicate, stale Nov 13, 2024
EpicEric added a commit to EpicEric/russh that referenced this issue Nov 14, 2024
In Eugeny#373 I raised my confusion about the lack of a disconnection
mechanism in the source code and the examples, but it was pointed out
that `Drop` is the intended way of cleaning up resources.

This PR adds a Drop implementation for three of the server examples,
so that users that refer to these won't be confused about how to
implement their own cleanup.
Eugeny pushed a commit that referenced this issue Nov 14, 2024
In #373 I raised my confusion about the lack of a disconnection
mechanism in the source code and the examples, but it was pointed out
that `Drop` is the intended way of cleaning up resources.

This PR adds a Drop implementation for three of the server examples, so
that users that refer to these won't be confused about how to implement
their own cleanup.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants