Repository navigation
fix(adapter): do not retain unused namespaces with connection state recovery - #5653
Open
imeerkhurram wants to merge 1 commit into
Open
imeerkhurram wants to merge 1 commit into
imeerkhurram wants to merge 1 commit into
Conversation
…ecovery The SessionAwareAdapter class started an interval in its constructor and never cleared it, which prevented the adapter (and its namespace) from being garbage-collected once closed, for example when the cleanupEmptyChildNamespaces option is enabled.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
The kind of change this PR does introduce
Current behavior
SessionAwareAdapterstarts an interval in its constructor and never clears it. The interval holds the adapter, and the adapter holds its namespace, so withconnectionStateRecoveryenabled a child namespace removed bycleanupEmptyChildNamespacescan never be garbage-collected:I connected and disconnected one client on each of 50 such namespaces, then forced a GC and counted the namespaces that were still alive: 50 of 50. Without
connectionStateRecoveryit is 0 of 50.New behavior
The timer is started when the first session or packet is stored, stops once both are empty, and is cleared in
close(). The same script now reports 0 of 50.I did not only clear it in
close(), because a server can be used again afterio.close()withio.listen(). The timer would then never come back andpacketswould grow forever. A broadcast from adisconnecthandler (which runs after the adapter is closed) starts it again, and it stops by itself when the packet expires.Other information (e.g. related issues)
Tests added in
packages/socket.io-adapter/test/index.ts, they fail without the change. I also ran the suites ofsocket.io,socket.io-client, the cluster adapter, the cluster engine and both emitters (Redis 7 and Postgres running locally).