From e316a82f86594d8030f7330fdb08c259e6fdb7a1 Mon Sep 17 00:00:00 2001 From: John Lees-Miller Date: Sat, 23 Jan 2021 21:05:30 +0000 Subject: [PATCH] Fix hang on double close --- lib/faye/websocket/api.js | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/lib/faye/websocket/api.js b/lib/faye/websocket/api.js index 13a8021..d64cb03 100644 --- a/lib/faye/websocket/api.js +++ b/lib/faye/websocket/api.js @@ -105,12 +105,14 @@ var instance = { "The code must be either 1000, or between 3000 and 4999. " + code + " is neither."); - if (this.readyState !== API.CLOSED) this.readyState = API.CLOSING; - var self = this; + if (this.readyState < API.CLOSING) { + var self = this; + this._closeTimer = setTimeout(function() { + self._beginClose('', 1006); + }, API.CLOSE_TIMEOUT); + } - this._closeTimer = setTimeout(function() { - self._beginClose('', 1006); - }, API.CLOSE_TIMEOUT); + if (this.readyState !== API.CLOSED) this.readyState = API.CLOSING; this._driver.close(reason, code); },