Fix crash on terminal close

Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
Sebastian Malton committed 2021-12-03 10:01:37 -05:00
1 parent d73df7fe0d
commit 223149d13c
2 files changed
+11 -3

No files matched your search

+4
View File
@@ -269,6 +269,10 @@ export abstract class ShellSession {
break; break;
} }
} catch (error) { } catch (error) {
if (error?.message === "ioctl(2) failed, EBADF") {
return;
}
logger.error(`[SHELL-SESSION]: failed to handle message for ${this.terminalId}`, error); logger.error(`[SHELL-SESSION]: failed to handle message for ${this.terminalId}`, error);
} }
}) })
+7 -3
View File
@@ -143,11 +143,14 @@ export class WebSocketApi<Events extends WebSocketEvents> extends (EventEmitter
} }
destroy() { destroy() {
if (!this.socket) return; if (!this.socket) {
return;
}
this.clearAllListeners();
this.socket.close(); this.socket.close();
this.socket = null; this.socket = null;
this.pendingCommands = []; this.pendingCommands = [];
this.clearAllListeners();
clearTimeout(this.reconnectTimer); clearTimeout(this.reconnectTimer);
clearInterval(this.pingTimer); clearInterval(this.pingTimer);
this.readyState = WebSocketApiState.PENDING; this.readyState = WebSocketApiState.PENDING;
@@ -197,7 +200,8 @@ export class WebSocketApi<Events extends WebSocketEvents> extends (EventEmitter
if (error) { if (error) {
const { reconnectDelay } = this.params; const { reconnectDelay } = this.params;
if (reconnectDelay) { // Only reconnect if the socket is still present (wasn't a WebSocket.destory() call)
if (reconnectDelay && this.socket) {
const url = this.socket.url; const url = this.socket.url;
this.writeLog("will reconnect in", `${reconnectDelay}s`); this.writeLog("will reconnect in", `${reconnectDelay}s`);