Skip to content

Commit 14deb46

Browse files
divybotlittledivy
andauthored
chore: regression test for KV panic on uncaught error with listenQueue (#34553)
## Summary Locks in the fix for [#20464](#20464): opening a KV, attaching `listenQueue()` without `await`, and then hitting an uncaught error on the main task used to panic the runtime with `Attempted to use a closed database` (at `ext/kv/sqlite.rs:440` in 1.36.4) while the queue's dequeue loop raced against the dropped SQLite connection. The 2023 reporter triggered it from Fresh's `dev.ts` (a `ReferenceError: Cannot access 'manifest' before initialization` followed by `await start(manifest, config)`), but the underlying race was generic to any uncaught error on the main task while `listenQueue` was outstanding. The runtime now unwinds cleanly: the JS error surfaces, the process exits non-zero, and there is no panic. This spec test pins that behavior so the property isn't lost silently if the queue/close ordering is refactored again. The new spec mirrors the reporter's setup: open `Deno.openKv(":memory:")`, fire `kv.listenQueue(() => {})` without `await`, log `Listening for messages...`, then `throw new Error(...)`. The test asserts exit code 1 and the JS error in stderr — any future regression that brings back the panic would change exit status and add a `Deno has panicked` block to the output. ## Test plan - [x] `target/debug/deps/specs-* kv_listen_queue_uncaught_error` passes locally - [x] Verified `deno run --watch` against the same reproducer prints the JS error and waits for a file change with no panic / no backtrace Closes denoland/orchid#299 Co-authored-by: divybot <divybot@users.noreply.github.com> Co-authored-by: Divy Srivastava <me@littledivy.com>
1 parent da3c9ec commit 14deb46

3 files changed

Lines changed: 25 additions & 0 deletions

File tree

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"tempDir": true,
3+
"args": "run -A --unstable-kv main.ts",
4+
"exitCode": 1,
5+
"output": "main.out"
6+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Listening for messages...
2+
error: Uncaught (in promise) Error: kaboom from main
3+
[WILDCARD]
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Copyright 2018-2026 the Deno authors. MIT license.
2+
3+
// Regression test for https://github.com/denoland/deno/issues/20464
4+
// Opening a KV, attaching listenQueue() without await, and then hitting an
5+
// uncaught error on the main task used to panic the runtime with
6+
// "Attempted to use a closed database" while the queue's dequeue loop raced
7+
// against the dropped SQLite connection. The error path must now unwind
8+
// cleanly: surface the JS error, exit non-zero, no panic.
9+
10+
const kv = await Deno.openKv(":memory:");
11+
kv.listenQueue(() => {});
12+
console.log("Listening for messages...");
13+
14+
// Mirror the reporter's "Cannot access 'manifest' before initialization"
15+
// — any uncaught error on the main task is enough to expose the race.
16+
throw new Error("kaboom from main");

0 commit comments

Comments
 (0)