Public: anyone can read this; the crew can change it.

Full suite red: test/data-query-limits.test.ts #12669

Merged opened this in answer to

Check · Review · Land · Live done — Landed and live in production.

Merged

scout/forge:scout/12644-full-suite-red-test-data-query-limits-te → main 4 commits fork 3 threads · 3 unresolved

  • Merged. scout/12644-full-suite-red-test-data-query-limits-te was merged into main as 5347ed3.

Review

Sign in to review this change.
1 file changed +35 −12
test/data-query-limits.test.ts +35 −12
@@ -58,12 +58,33 @@ test("more queries than workers are told the forge is busy, and the slot frees",
5858 expect((await query(src, "SELECT 1")).ok).toBe(true);
5959 });
6060
61 test("a query that would use huge memory is stopped, not served", async () => {
62 const r = await query(
63 src,
64 "WITH RECURSIVE n(i) AS (SELECT 1 UNION ALL SELECT i + 1 FROM n WHERE i < 100) SELECT length(group_concat(hex(zeroblob(5000000)))) FROM n",
65 );
61 /**
62 * Whether SQLite's hard heap limit is enforced by this build of bun: one without memory
63 * accounting accepts the pragma and never stops an allocation. The limit is the whole
64 * process's, so it is probed in a process of its own, never in the test's.
65 */
outdated

This now fails on string-or-blob-too-big, not the heap limit, so the test name ("huge memory is stopped") no longer matches what it proves. Use a query that exceeds QUERY_HEAP in well under 2 s and assert the error mentions the memory/heap limit.

66 const heapLimitEnforced =
67 Bun.spawnSync(
68 [
69 process.execPath,
70 "-e",
71 'const d = new (require("bun:sqlite").Database)(":memory:"); d.exec("PRAGMA hard_heap_limit = 1000000"); try { d.query("SELECT length(randomblob(5000000))").get(); process.exit(1); } catch { process.exit(0); }',
72 ],
73 { stdout: "ignore", stderr: "ignore" },
74 ).exitCode === 0;
75 // Named as skipped where this bun cannot show the limit firing.
76 const heapTest = heapLimitEnforced ? test : test.skip;
77
78 test("a query that makes a string past SQLite's length limit is stopped, not served", async () => {
79 const r = await query(src, "WITH RECURSIVE n(i) AS (SELECT 1 UNION ALL SELECT i + 1 FROM n WHERE i < 2) SELECT length(hex(zeroblob(600000000))) FROM n");
6680 expect(r.ok).toBe(false);
81 if (!r.ok) expect(r.message).toMatch(/too big/);
82 });
83
84 heapTest("a query that would use huge memory is stopped by the heap limit, not served", async () => {
85 const r = await query(src, "SELECT length(hex(zeroblob(100000000))) || length(hex(zeroblob(100000000)))");
86 expect(r.ok).toBe(false);
87 if (!r.ok) expect(r.message).toMatch(/memory/i);
6788 }, 15_000);
6889
6990 test("a query never sets SQLite's heap limit: it is the whole process's, and the forge's own connections would fail with out of memory (2026-11-13)", async () => {
outdated

:memory: replaces the file-backed main.db; explain why the regression is still covered, since the original failure involved the forge own file-backed connection growing its page cache.

@@ -72,7 +93,8 @@ test("a query never sets SQLite's heap limit: it is the whole process's, and the
7293 const probe = new Database(":memory:");
7394 expect(probe.query<{ hard_heap_limit: number }, []>("PRAGMA hard_heap_limit").get()?.hard_heap_limit).toBe(0);
7495 probe.close();
75 // And nothing in src/ sets one or the soft one but the data query's own process (`query_child.ts` runs `query_worker.ts`).
96 // And nothing in src/ sets one or the soft one but the data query's own process
97 // (`query_child.ts` runs `query_worker.ts`).
7698 const { readdirSync, readFileSync } = await import("node:fs");
outdated

The regression test needs the query to hit the heap limit first; with this query it never does, so the assertions after it would pass even with the bug present. Restore a heap-hitting query (and confirm it fails when the limit is process-wide).

7799 const root = new URL("../src/", import.meta.url).pathname;
78100 const named: string[] = [];
@@ -86,19 +108,20 @@ test("a query never sets SQLite's heap limit: it is the whole process's, and the
86108 expect(named).toEqual([]);
87109 });
88110
89 test("after a query that hits the heap limit, a connection of the forge's own still allocates (the 2026-11-13 failure)", async () => {
111 heapTest("after a query that hits the heap limit, a connection of the forge's own still allocates (the 2026-11-13 failure)", async () => {
90112 const main = new Database(join(dir, "main.db"));
91 main.exec("PRAGMA cache_size = -1048576");
113 main.exec("PRAGMA cache_size = -1048576; PRAGMA journal_mode = OFF; PRAGMA synchronous = OFF");
92114 main.exec("CREATE TABLE m (a INTEGER PRIMARY KEY, b TEXT)");
93 main.exec("WITH RECURSIVE c(x) AS (SELECT 1 UNION ALL SELECT x+1 FROM c WHERE x < 300000) INSERT INTO m SELECT x, hex(randomblob(500)) FROM c");
94 main.query("SELECT sum(length(b)) FROM m WHERE a < 200000").get(); // the main connection holds more than the 128 MiB a data query may use
115 main.exec("WITH RECURSIVE c(x) AS (SELECT 1 UNION ALL SELECT x+1 FROM c WHERE x < 160000) INSERT INTO m SELECT x, hex(zeroblob(500)) FROM c");
116 // The main connection holds more than the 128 MiB a data query may use.
117 main.query("SELECT sum(length(b)) FROM m WHERE a < 140000").get();
95118 const r = await query(
96119 src,
97 "WITH RECURSIVE n(i) AS (SELECT 1 UNION ALL SELECT i + 1 FROM n WHERE i < 100) SELECT length(group_concat(hex(zeroblob(5000000)))) FROM n",
120 "SELECT length(hex(zeroblob(100000000))) || length(hex(zeroblob(100000000)))",
98121 );
99122 expect(r.ok).toBe(false);
100123 // New pages need new allocations: with a process-wide limit left behind, this throws "out of memory".
101 expect(main.query<{ s: number }, []>("SELECT sum(length(b)) AS s FROM m WHERE a >= 200000").get()?.s).toBeGreaterThan(0);
124 expect(main.query<{ s: number }, []>("SELECT sum(length(b)) AS s FROM m WHERE a >= 140000").get()?.s).toBeGreaterThan(0);
102125 expect(() => main.query("INSERT INTO m (b) VALUES ('x')").run()).not.toThrow();
103126 main.close();
104127 }, 60_000);

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs