summaryrefslogtreecommitdiff
path: root/cli/tests/unit
diff options
context:
space:
mode:
authorDivy Srivastava <dj.srivastava23@gmail.com>2024-01-09 19:56:54 +0530
committerGitHub <noreply@github.com>2024-01-09 19:56:54 +0530
commit6db631a432ee916380b62770357adb46edd7c281 (patch)
tree7374d69b2f26bc66f82a81db069963b0c0b14e37 /cli/tests/unit
parent19c10c024623a227bc68b6606bc2f32d25030ab7 (diff)
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).
Diffstat (limited to 'cli/tests/unit')
-rw-r--r--cli/tests/unit/websocket_test.ts30
1 files changed, 30 insertions, 0 deletions
diff --git a/cli/tests/unit/websocket_test.ts b/cli/tests/unit/websocket_test.ts
index 47d056492..6a1dc3525 100644
--- a/cli/tests/unit/websocket_test.ts
+++ b/cli/tests/unit/websocket_test.ts
@@ -405,3 +405,33 @@ Deno.test(
await Promise.all([deferred.promise, server.finished]);
},
);
+
+Deno.test(
+ { sanitizeOps: false },
+ async function websocketServerGetsGhosted() {
+ const ac = new AbortController();
+ const listeningDeferred = Promise.withResolvers<void>();
+
+ const server = Deno.serve({
+ handler: (req) => {
+ const { socket, response } = Deno.upgradeWebSocket(req, {
+ idleTimeout: 2,
+ });
+ socket.onerror = () => socket.close();
+ socket.onclose = () => ac.abort();
+ return response;
+ },
+ signal: ac.signal,
+ onListen: () => listeningDeferred.resolve(),
+ hostname: "localhost",
+ port: servePort,
+ });
+
+ await listeningDeferred.promise;
+ const r = await fetch("http://localhost:4545/ghost_ws_client");
+ assertEquals(r.status, 200);
+ await r.body?.cancel();
+
+ await server.finished;
+ },
+);