Guard CloudProvider._sendCloudData against a cleared connection#10061
Open
Chessing234 wants to merge 1 commit intoscratchfoundation:developfrom
Open
Guard CloudProvider._sendCloudData against a cleared connection#10061Chessing234 wants to merge 1 commit intoscratchfoundation:developfrom
Chessing234 wants to merge 1 commit intoscratchfoundation:developfrom
Conversation
CloudProvider.sendCloudData is a lodash throttled wrapper around
_sendCloudData (see the constructor's `throttle(this._sendCloudData,
100)`), so a send can be deferred by up to 100ms. In the meantime the
owner can call requestCloseConnection / clear, which sets
this.connection = null. When the deferred throttle fires it runs
this.connection.send(`${data}\n`);
on a now-null connection and throws
"Cannot read properties of null (reading 'send')".
The call sites that schedule this send (writeToServer and the onOpen
queue flush) already check `this.connection` before queueing, so they
were relying on the connection still existing when the throttled call
eventually runs - which is exactly what clear() breaks. Wrap the
actual send in an `if (this.connection)` guard so a late throttled
call after clear() becomes a no-op instead of a crash.
|
I have read the CLA Document and I hereby sign the CLA You can retrigger this bot by commenting recheck in this Pull Request. Posted by the CLA Assistant Lite bot. |
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.
Bug
CloudProvider._sendCloudDatathrowsTypeError: Cannot read properties of null (reading 'send')when apreviously-scheduled cloud-data send fires after the provider has
been cleared (e.g. the user navigates away from a project or
requestCloseConnection()is called while messages are still inflight).
Root cause
The constructor wraps
_sendCloudDatain a 100 ms lodash throttle:so a call to
sendCloudData(data)can be deferred by up to 100 ms.In that window the owner can run
requestCloseConnection(), whichcalls
clear():When the throttle's trailing call finally fires it hits
_sendCloudData:this.connectionis nownull, so.sendexplodes. The call sitesthat schedule the send (
writeToServerand theonOpenqueue flush)already check
this.connectionbefore queueing, but they cannotspeak for what the connection is when the throttle trailing-edge
actually executes.
Why the fix is correct
.sendwithif (this.connection)makes alate-arriving throttled call a no-op instead of a crash; messages
targeted at an already-closed connection were going to be dropped
anyway (the server can't receive them).
send exactly as before.
in the post-
clear()race window that was previously crashing.Change
src/lib/cloud-provider.js: wrapthis.connection.send(\${data}\n`)in anif (this.connection)` guard.