Correctly identify and clean taken-over sessions #180
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
An issue was highlighted in which the subscriptions for a client which has undertaken a session takeover could be cleared erroneously in #173.
This behaviour was caused by the orphaned client unsubscribing from the client's topics after the new client had already inherited the subscriptions and begun reading.
Additionally, I identified a secondary, more significant issue in which an expiring orphaned client would delete the existing client from the server client map.
This PR attempts to resolve this issue through three mechanisms:
isTakenOver
atomic bit switch to the client which is set to 1 when the client session is inherited by a new client and the client is orphaned (the pointer to the client has been, or shortly will be overwritten in the server client map).Finally, the state of existing sessions is cleaned up on all inheritance to prevent sequential take-overs from increasing memory usage by inflights + subs * client-id.
This PR adds a new test case specifically to ensure client inheritance and state cleaning is performed as expected.