Skip to content

bun:sqlite: finalize outstanding prepared statements on close via sqlite3_next_stmt - #36573

Merged
Jarred-Sumner merged 14 commits into
mainfrom
farm/e40075e8/sqlite-close-query-overflow
Aug 2, 2026
Merged

bun:sqlite: finalize outstanding prepared statements on close via sqlite3_next_stmt#36573
Jarred-Sumner merged 14 commits into
mainfrom
farm/e40075e8/sqlite-close-query-overflow

sqlite: track statement wrappers per connection and null their handle…

abeabc8
Select commit
Loading
Failed to load commit list.
Claude / Claude Code Review completed Aug 2, 2026 in 30m 15s

Code review found 1 potential issue

Found 3 candidates, confirmed 1. See review comments for details.

Details

Severity Count
🔴 Important 0
🟡 Nit 1
🟣 Pre-existing 0
Severity File:Line Issue
🟡 Nit src/jsc/bindings/sqlite/JSSQLStatement.cpp:2883-2885 removeFirst() on WTF::Vector gives O(n²) unlink when GC sweeps many statement wrappers

Annotations

Check warning on line 2885 in src/jsc/bindings/sqlite/JSSQLStatement.cpp

See this annotation in the file changed.

@claude claude / Claude Code Review

removeFirst() on WTF::Vector gives O(n²) unlink when GC sweeps many statement wrappers

nit: `VersionSqlite3::statements` is a `WTF::Vector`, so `~JSSQLStatement()` unlinking via `removeFirst(this)` is a linear scan + memmove — sweeping N unreferenced wrappers before `close()` is O(n²). Both reference implementations the comment at line 219 cites (better-sqlite3's `CloseHandles()`, node:sqlite's `FinalizeStatements()`) use `std::set` for O(log n) unlink; since iteration order is never observed, `WTF::HashSet<JSSQLStatement*>` (`add` in `create()`, `remove` here, range-for in `close