-
Notifications
You must be signed in to change notification settings - Fork 833
Changed the remove method to work of a session instead of a clientID #915
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
base: main
Are you sure you want to change the base?
Changed the remove method to work of a session instead of a clientID #915
Conversation
|
@hylkevds do you know when this happen in production? For example is this a valid case that manifest the problem?
If that's the case, is it possible to write an integration test to cover it? |
That specific case is covered. When client_1 is still connected, when client_2 connects with the same ClientId, client_1 will be disconnected, and depending on the clean_session setting, the old Session will be cleaned up before the new one is created. Though the call to The tricky issue would be when The correct solution would be to make the cleanup happen on the SessionLoop, and add a simple check to see if the session is actually connected. A connected session should never be removed. |
andsel
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that if it's a race condition then has to be managed with proper synchronization strategy.
|
Yes, hence why we should move the cleanup to the SessionLoop. Though the currently missing |
The client may have started a new session before the old one is purged, therefore the purge must check if the session being removed should actually be removed and is not a new session.
e9e6713 to
1de0990
Compare
|
I've had another look and made two additional changes:
Regarding tests, unfortunately, race conditions are nearly impossible to reliably test, since they depend on the exact interleaving of threads... |
The client may have started a new session before the old one is purged, therefore the purge must check if the session being removed should actually be removed and is not a new session.
By basing the remove method on the session instead of the client id, it can ensure only the correct session is removed from the pool.