fix(ext/websocket): pass on uncaught errors in idleTimeout (#21846)

Fixes https://github.com/denoland/deno/issues/21840

The problem was hard to reproduce as its a race condition. I've added a
test that reproduces the problem 1/10 tries. We should move the
idleTimeout handling to Rust (maybe even built into fastwebsocket).
This commit is contained in:
Divy Srivastava 2024-01-09 19:56:54 +05:30 committed by GitHub
parent 19c10c0246
commit 6db631a432
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 83 additions and 2 deletions

View file

@ -502,12 +502,15 @@ class WebSocket extends EventTarget {
clearTimeout(this[_idleTimeoutTimeout]);
this[_idleTimeoutTimeout] = setTimeout(async () => {
if (this[_readyState] === OPEN) {
await op_ws_send_ping(this[_rid]);
await PromisePrototypeCatch(op_ws_send_ping(this[_rid]), () => {});
this[_idleTimeoutTimeout] = setTimeout(async () => {
if (this[_readyState] === OPEN) {
this[_readyState] = CLOSING;
const reason = "No response from ping frame.";
await op_ws_close(this[_rid], 1001, reason);
await PromisePrototypeCatch(
op_ws_close(this[_rid], 1001, reason),
() => {},
);
this[_readyState] = CLOSED;
const errEvent = new ErrorEvent("error", {