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:
parent
ba13b8e2a9
commit
a0a13b3a1b
1 changed files with 28 additions and 20 deletions
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue