From d50cfc1f2b86b64b2f9715dd681bc43bacab1f31 Mon Sep 17 00:00:00 2001 From: Andrew Thomas Date: Thu, 1 Jun 2017 11:54:35 -0700 Subject: [PATCH 1/3] adds an initial state to the socket state --- src/wire/Socket.ts | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/wire/Socket.ts b/src/wire/Socket.ts index d045854..78c756e 100644 --- a/src/wire/Socket.ts +++ b/src/wire/Socket.ts @@ -110,7 +110,7 @@ export class InteractiveSocket extends EventEmitter { private reconnectTimeout: NodeJS.Timer; private options: ISocketOptions; - private state: SocketState; + private state: SocketState = SocketState.Idle; private socket: any; private queue: Set = new Set(); @@ -249,10 +249,12 @@ export class InteractiveSocket extends EventEmitter { return; } - this.state = SocketState.Closing; - this.socket.close(1000, 'Closed normally.'); - this.queue.forEach(packet => packet.cancel()); - this.queue.clear(); + if (this.state !== SocketState.Idle) { + this.state = SocketState.Closing; + this.socket.close(1000, 'Closed normally.'); + this.queue.forEach(packet => packet.cancel()); + this.queue.clear(); + } } /** From 8de1c04b3f370b9f3381cc4c14657b3e2707f968 Mon Sep 17 00:00:00 2001 From: Andrew Thomas Date: Fri, 2 Jun 2017 09:16:19 -0700 Subject: [PATCH 2/3] closes if conditional fails --- src/wire/Socket.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/wire/Socket.ts b/src/wire/Socket.ts index 78c756e..e762c88 100644 --- a/src/wire/Socket.ts +++ b/src/wire/Socket.ts @@ -254,6 +254,8 @@ export class InteractiveSocket extends EventEmitter { this.socket.close(1000, 'Closed normally.'); this.queue.forEach(packet => packet.cancel()); this.queue.clear(); + } else { + this.state = SocketState.Closing; } } From ffc35afae9b92b89491d7a3671e4dba01131c7d6 Mon Sep 17 00:00:00 2001 From: Andrew Thomas Date: Mon, 5 Jun 2017 14:24:55 -0700 Subject: [PATCH 3/3] removes else --- src/wire/Socket.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/wire/Socket.ts b/src/wire/Socket.ts index e762c88..78c756e 100644 --- a/src/wire/Socket.ts +++ b/src/wire/Socket.ts @@ -254,8 +254,6 @@ export class InteractiveSocket extends EventEmitter { this.socket.close(1000, 'Closed normally.'); this.queue.forEach(packet => packet.cancel()); this.queue.clear(); - } else { - this.state = SocketState.Closing; } }