summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ext/websocket/01_websocket.js48
1 files changed, 28 insertions, 20 deletions
diff --git a/ext/websocket/01_websocket.js b/ext/websocket/01_websocket.js
index 3585256fc..8c407dff8 100644
--- a/ext/websocket/01_websocket.js
+++ b/ext/websocket/01_websocket.js
@@ -481,28 +481,36 @@
if (this[_idleTimeoutDuration]) {
clearTimeout(this[_idleTimeoutTimeout]);
this[_idleTimeoutTimeout] = setTimeout(async () => {
- await core.opAsync("op_ws_send", this[_rid], {
- kind: "ping",
- });
- this[_idleTimeoutTimeout] = setTimeout(async () => {
- this[_readyState] = CLOSING;
- const reason = "No response from ping frame.";
- await core.opAsync("op_ws_close", this[_rid], 1001, reason);
- this[_readyState] = CLOSED;
-
- const errEvent = new ErrorEvent("error", {
- message: reason,
+ if (this[_readyState] === OPEN) {
+ await core.opAsync("op_ws_send", this[_rid], {
+ kind: "ping",
});
- this.dispatchEvent(errEvent);
+ this[_idleTimeoutTimeout] = setTimeout(async () => {
+ if (this[_readyState] === OPEN) {
+ this[_readyState] = CLOSING;
+ const reason = "No response from ping frame.";
+ await core.opAsync("op_ws_close", this[_rid], 1001, reason);
+ this[_readyState] = CLOSED;
- const event = new CloseEvent("close", {
- wasClean: false,
- code: 1001,
- reason,
- });
- this.dispatchEvent(event);
- core.tryClose(this[_rid]);
- }, (this[_idleTimeoutDuration] / 2) * 1000);
+ const errEvent = new ErrorEvent("error", {
+ message: reason,
+ });
+ this.dispatchEvent(errEvent);
+
+ const event = new CloseEvent("close", {
+ wasClean: false,
+ code: 1001,
+ reason,
+ });
+ this.dispatchEvent(event);
+ core.tryClose(this[_rid]);
+ } else {
+ clearTimeout(this[_idleTimeoutTimeout]);
+ }
+ }, (this[_idleTimeoutDuration] / 2) * 1000);
+ } else {
+ clearTimeout(this[_idleTimeoutTimeout]);
+ }
}, (this[_idleTimeoutDuration] / 2) * 1000);
}
}