0
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2025-03-03 09:31:22 -05:00

fix(http/upgradewebsocket): check for open state for idle timeout (#14813)

This commit is contained in:
Leo Kettmeir 2022-06-08 17:52:23 +02:00 committed by GitHub
parent ba13b8e2a9
commit a0a13b3a1b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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);
}
}