From a112c3b45ca8a9041f17897489f2e53256da4481 Mon Sep 17 00:00:00 2001 From: Steve-Mcl Date: Thu, 11 Jan 2024 13:58:19 +0000 Subject: [PATCH] improve auto tunnel reconnect --- lib/editor/tunnel.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/lib/editor/tunnel.js b/lib/editor/tunnel.js index 02bae50..1f96408 100644 --- a/lib/editor/tunnel.js +++ b/lib/editor/tunnel.js @@ -50,6 +50,7 @@ class EditorTunnel { async connect () { const thisTunnel = this + let unexpectedPacketMonitor = 0 if (this.socket) { this.close() } @@ -63,6 +64,7 @@ class EditorTunnel { } }) socket.onopen = (evt) => { + unexpectedPacketMonitor = 0 info('Editor tunnel connected') // Reset reconnectDelay this.reconnectDelay = 500 @@ -156,8 +158,13 @@ class EditorTunnel { wsClient.sendOrQueue(body) } } else { - warn(`[${request.id}] Unexpected editor comms packet ${JSON.stringify(request, null, 4)}`) - this.close(1006, 'Non-connect packet received for unknown connection id') // 1006 = Abnormal closure + if (unexpectedPacketMonitor > 1) { + unexpectedPacketMonitor = 0 + warn(`[${request.id}] Unexpected editor comms packet ${JSON.stringify(request, null, 4)}`) + this.close(1006, 'Non-connect packet received for unknown connection id') // 1006 = Abnormal closure + } else { + unexpectedPacketMonitor++ + } } } else { // An http related event