From 3e0feee846c9ffc4082d3c5b8995b7c7b7c903ee Mon Sep 17 00:00:00 2001 From: Taksh Date: Mon, 20 Apr 2026 18:36:08 +0530 Subject: [PATCH] Guard _sendCloudData against a cleared connection 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. --- src/lib/cloud-provider.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/lib/cloud-provider.js b/src/lib/cloud-provider.js index ce26082fcf4..70e656832e7 100644 --- a/src/lib/cloud-provider.js +++ b/src/lib/cloud-provider.js @@ -154,7 +154,9 @@ class CloudProvider { * @param {string} data The formatted message to send. */ _sendCloudData (data) { - this.connection.send(`${data}\n`); + if (this.connection) { + this.connection.send(`${data}\n`); + } } /**