Skip to content

Add the socket listeners once, not once per initialize() - #827

Closed
cmdcolin wants to merge 1 commit into
mainfrom
socket-listeners-added-once
Closed

Add the socket listeners once, not once per initialize()#827
cmdcolin wants to merge 1 commit into
mainfrom
socket-listeners-added-once

Conversation

@cmdcolin

Copy link
Copy Markdown

Same root cause as #826 but a worse symptom: addSocketListeners registers each handler as a fresh arrow function, so socket.io cannot recognize a repeat and it does not no-op the way the addEventListener calls at the end of initialize() do — and initialize() can run more than once, since the autorun in afterAttach disposes only after the awaits either side of it and deliberately does not on failure.

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, so this guards on socketListenersAdded alongside 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

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.
@cmdcolin

Copy link
Copy Markdown
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.

@cmdcolin

Copy link
Copy Markdown
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.

@cmdcolin cmdcolin closed this Aug 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant