summaryrefslogtreecommitdiff
path: root/ext/websocket/01_websocket.js
diff options
context:
space:
mode:
authorLeo Kettmeir <crowlkats@toaxl.com>2022-06-08 17:52:23 +0200
committerGitHub <noreply@github.com>2022-06-08 17:52:23 +0200
commita0a13b3a1b5b654ad36a25c4785cab539555840a (patch)
tree740c39bce58dcc1780b875176cac2905eb266278 /ext/websocket/01_websocket.js
parentba13b8e2a9efff13e4a7c0659bb2ed184cc4e683 (diff)
fix(http/upgradewebsocket): check for open state for idle timeout (#14813)
Diffstat (limited to 'ext/websocket/01_websocket.js')
-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);
}
}