Skip to content

Commit

Permalink
Ensure cancel reconnection timeout when reconnected and don't schedul…
Browse files Browse the repository at this point in the history
…e more than one.
  • Loading branch information
GrahamDumpleton committed May 9, 2022
1 parent b071d51 commit 55cc832
Showing 1 changed file with 15 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ class TerminalSession {
private blocked: boolean
private buffer: string[]
private reconnecting: boolean
private reconnectTimer: any
private shutdown: boolean

constructor(context: string, id: string, element: HTMLElement, endpoint: string) {
Expand Down Expand Up @@ -205,6 +206,12 @@ class TerminalSession {

console.log("Connection opened to terminal", this.id)

if (this.reconnectTimer) {
console.log("Clear reconnection timeout for terminal", this.id)
clearTimeout(this.reconnectTimer)
this.reconnectTimer = null
}

if (socket !== this.socket) {
console.warn("Multiple connections to terminal", this.id)
socket.close()
Expand Down Expand Up @@ -514,6 +521,8 @@ class TerminalSession {
setTimeout(connect, 100)

function terminate() {
self.reconnectTimer = null

if (!self.reconnecting)
return

Expand Down Expand Up @@ -566,9 +575,9 @@ class TerminalSession {
}

if (!this.reconnecting) {
console.log("Schedule abandoning of terminal", self.id)
console.log("Trigger reconnection timeout for terminal", self.id)

setTimeout(terminate, 10000)
self.reconnectTimer = setTimeout(terminate, 10000)

this.reconnecting = true
}
Expand Down Expand Up @@ -708,6 +717,8 @@ class TerminalSession {
setTimeout(connect, 100)

function terminate() {
self.reconnectTimer = null

if (!self.reconnecting)
return

Expand All @@ -720,9 +731,9 @@ class TerminalSession {
}

if (!this.reconnecting) {
console.log("Schedule abandoning of terminal", self.id)
console.log("Trigger reconnection timeout for terminal", self.id)

setTimeout(terminate, 5000)
self.reconnectTimer = setTimeout(terminate, 5000)

this.reconnecting = true
}
Expand Down

0 comments on commit 55cc832

Please sign in to comment.