fix(socketio): latch connectionRejected and switch handshake scheme - #406
Open
RobertoReale wants to merge 1 commit into
Open
fix(socketio): latch connectionRejected and switch handshake scheme#406RobertoReale wants to merge 1 commit into
RobertoReale wants to merge 1 commit into
Conversation
On overleaf.com the socket.io handshake is only accepted with the `?projectId=...` query flag (scheme v2). The plain handshake (v1) connects and is then rejected with `connectionRejected`. The socket is created by the `SocketIOAPI` constructor, so that rejection normally arrives *before* `joinProject` is called: the listener registered inside `joinProject` never sees it, the scheme is never switched, and every later operation fails with a 5s timeout (`Unable to write file ... (timeout)`). Handle the event where it is actually received: - latch the rejection in `_connectionRejected` and let `needsReinit` report that the socket must be recreated; - track which schemes were rejected, so v1 falls back to v2 and v2 back to v1 without ping-ponging; - fail any in-flight and any subsequent `joinProject` immediately instead of waiting for the timeout; - disable auto-reconnect through `stopAutoReconnect()`, which also works on socket.io-client 0.9.x (the bundled version), where the reconnect flag lives in `socket.socket.options` and not in `socket.io`; - clear the rejected-scheme set once a join succeeds.
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.
Fixes #234
Refs #380, refs #351 — both report the same log line,
SocketIOAPI: connectionRejected. missing/bad ?projectId=... query flag on handshake, whose cause is fixed here; whether it accounts for the whole of #380 (the "Open Project Locally" dialog not appearing) I cannot say.Problem
On overleaf.com the socket.io handshake is only accepted with the
?projectId=...query flag (schemev2). With the plain handshake (v1) the socket connects and is then rejected withconnectionRejected.The socket is created by the
SocketIOAPIconstructor, so that rejection normally arrives beforejoinProjectis ever called. The fallback logic lives in a listener registered insidejoinProject, which therefore never sees the event: the scheme is never switched, the socket stays in the rejected state, and every later operation only fails through its 5 s timeout — the user sees a spinning compile, orUnable to write file ... (timeout)on save.Trace from a run against overleaf.com, before this change:
A second detail: the existing code disables auto-reconnect through
this.socket.io.reconnect(false), which is the socket.io-client >= 1.x API. The extension bundles 0.9.17-overleaf-5, wherethis.socketis aSocketNamespaceand the flag lives inthis.socket.socket.options.reconnect, so the call is a no-op and the rejected socket keeps reconnecting.Change
In the
connectionRejectedhandler, i.e. where the event is actually received:_connectionRejected, and letneedsReinitreport that the socket must be recreated;_rejectedSchemes), sov1falls back tov2andv2back tov1without ping-ponging between them; the set is cleared once a join succeeds;joinProjectimmediately through_rejectionWaiters, and reject a laterjoinProjectright away if the rejection is already latched, instead of waiting 5 s for the timeout;stopAutoReconnect(), which handles both the 0.9.x namespace and the >= 1.x manager.joinProjectno longer registers its ownconnectionRejectedlistener (one per call, never removed).Verification
Against overleaf.com with a real project, 0.15.10 + this patch:
v1is rejected once, the client switches tov2,joinProjectResponsearrives, and opening files, editing and saving work. I could not test a self-hosted instance that only acceptsv1; that direction of the fallback is symmetric in the code but untested by me.Possibly related, but not verified by me: #399.