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

Sessions are not explicitly deleted after disconnect #18

Closed
ptrsmntc opened this issue Nov 6, 2019 · 3 comments
Closed

Sessions are not explicitly deleted after disconnect #18

ptrsmntc opened this issue Nov 6, 2019 · 3 comments

Comments

@ptrsmntc
Copy link

ptrsmntc commented Nov 6, 2019

New sessions are created on connect, then registered in the dictionary, and unregistered on disconnect, but never explicitly disposed.

Are you relying on the GC to dispose of the sessions?
Is this really a good idea as they contain managed resources, i.e. socket and state objects.

Since it is not possible to "delete this" in C# (as far as I know), typical async implementations would mark sessions as stale, and periodically delete all stale sessions, or mark them for reuse, in a timer or cleanup loop.

@chronoxor
Copy link
Owner

There is no need to dispose TcpSession/SslSession as they will dispose wrapped Socket in public virtual bool Disconnect() method. Other wrapped resources are not support IDisposable and will be managed by GC.

@ptrsmntc
Copy link
Author

ptrsmntc commented Nov 6, 2019

Ok, so the GC discards the managed part, and the explicit disconnect disposes the unmanaged objects so they do not linger and consume resources?

@chronoxor
Copy link
Owner

Sessions are disconnected by system network layer (e.g. when remote peer disconnects or network hangs) or when the server stops with DisconnectAll() method. As the result sockets resources will be disposed. But sessions objects and their buffers will be handled by GC later as they are not IDisposable.

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

2 participants