Skip to content

Commit

Permalink
improve auto tunnel reconnect
Browse files Browse the repository at this point in the history
  • Loading branch information
Steve-Mcl committed Jan 11, 2024
1 parent 4b2a621 commit a112c3b
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions lib/editor/tunnel.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ class EditorTunnel {

async connect () {
const thisTunnel = this
let unexpectedPacketMonitor = 0
if (this.socket) {
this.close()
}
Expand All @@ -63,6 +64,7 @@ class EditorTunnel {
}
})
socket.onopen = (evt) => {
unexpectedPacketMonitor = 0
info('Editor tunnel connected')
// Reset reconnectDelay
this.reconnectDelay = 500
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit a112c3b

Please sign in to comment.