Refactor AppSession to simplify improving reconnect behavior #5782
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.
Note:
developbranch rather thanfeature/session-manageras it doesn't hurtto merge it into
developand reduces the diff size of the feature branch.📚 Context
In the
feature/session-managerbranch, we're working towards improving the way that we handlewebsocket disconnects. As part of this work, we'll need to have the final steps of
AppSessioncleanup (done by the
shutdown()method) happen when a session is garbage collected ratherthan when the browser's websocket connection is dropped.
To make this easier, this PR splits out file changed handler registration/deregistration into two helper
methods. We also add a
__del__method toAppSession, which calls theshutdown()method ongarbage collection.
Finally, we add a test to make it harder to introduce
AppSession-related memory leaks related to filewatchers holding references to
AppSessionfile changed handler methods. This exact issue hascaused memory leaks in the past, so we should be extra-careful to avoid it given that our work to
defer
AppSessioncleanup is particularly prone to running into this.What kind of change does this PR introduce?
🧪 Testing Done