Add the socket listeners once, not once per initialize() - #827
Closed
cmdcolin wants to merge 1 commit into
Closed
Conversation
Each handler is a fresh arrow function, so socket.io cannot recognize a repeat and addSocketListeners does not no-op the way the addEventListener calls at the end of initialize() do. initialize() can run more than once — the autorun in afterAttach disposes only after the awaits either side of this call, and deliberately does not on failure — and a second registration means every COMMON message is submitted to the change manager twice, every connect_error raises two notifications, and every reconnect fetches the missing changes twice. Guard it with socketListenersAdded, alongside the socket it belongs to. The token check throws before anything is registered, so a run that failed on it leaves nothing behind and the retry still works.
Author
|
Superseded by #828 if that lands — it removes the need for this flag by separating the once-only work from the retryable work. Take either, not both. |
Author
|
Closing in favour of #828, which fixes the same defect for both effects at once — it separates the once-only startup work from the retryable work, so neither the socket listeners nor the menu call needs a flag. The branch stays if anyone wants to compare. |
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.
Same root cause as #826 but a worse symptom:
addSocketListenersregisters each handler as a fresh arrow function, so socket.io cannot recognize a repeat and it does not no-op the way theaddEventListenercalls at the end ofinitialize()do — andinitialize()can run more than once, since the autorun inafterAttachdisposes only after the awaits either side of it and deliberately does not on failure.A second registration means every
COMMONmessage is submitted to the change manager twice, everyconnect_errorraises two notifications, and every reconnect fetches the missing changes twice, so this guards onsocketListenersAddedalongside the socket it belongs to; the token check throws before anything is registered, so a run that failed on it still retries cleanly.🤖 Generated with Claude Code
https://claude.ai/code/session_01JXCNVXEZMYnkeTS6cjKYBy