From a6703ecb9839a3555bda9bb4b0b29d2b07a55e25 Mon Sep 17 00:00:00 2001 From: Asher Date: Tue, 2 Jul 2019 11:33:37 -0500 Subject: [PATCH] Prevent sending disconnect if disposed --- protocol.ts | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/protocol.ts b/protocol.ts index e9ddae77..b11ecfc5 100644 --- a/protocol.ts +++ b/protocol.ts @@ -13,6 +13,8 @@ export interface SocketOptions { } export class Protocol extends PersistentProtocol { + private disposed: boolean = false; + public constructor( secWebsocketKey: string, socket: net.Socket, @@ -40,12 +42,21 @@ export class Protocol extends PersistentProtocol { ].join("\r\n") + "\r\n\r\n"); } + public sendDisconnect(): void { + if (!this.disposed) { + super.sendDisconnect(); + } + } + public dispose(error?: Error): void { - if (error) { - this.sendMessage({ type: "error", reason: error.message }); + if (!this.disposed) { + this.disposed = true; + if (error) { + this.sendMessage({ type: "error", reason: error.message }); + } + super.dispose(); + this.getSocket().dispose(); } - super.dispose(); - this.getSocket().dispose(); } /** -- GitLab