Skip to content

fix: close database handles after failed open - #2

Open
marcus-pousette wants to merge 1 commit into
masterfrom
fix/close-failed-open-handle
Open

fix: close database handles after failed open#2
marcus-pousette wants to merge 1 commit into
masterfrom
fix/close-failed-open-handle

Conversation

@marcus-pousette

@marcus-pousette marcus-pousette commented Jul 14, 2026

Copy link
Copy Markdown
Owner

Why

SQLite can return a database handle even when sqlite3_open_v2 fails, and requires callers to close it. The wrapper currently tracks that failed handle and throws before callers can release it, potentially leaving OPFS resources or locks alive. It also registers extension functions before confirming that the open succeeded.

SQLite documents the failed-open cleanup requirement in sqlite3_open_v2.

What changes

  • Preserve the original open error before cleanup.
  • Best-effort close a handle returned by a failed open and remove it from JavaScript tracking.
  • Register extension functions only after a successful open.
  • Add regression coverage proving the failed handle is closed, untracked, and never passed to extension registration.

Merge order

This PR is based on the upstream 1.1.1 sync in #4. Merge #4 first, retarget this PR to master, then use Create a merge commit. TreeCRDT #210 pins this exact head, so it must remain reachable from the default branch.

@marcus-pousette
marcus-pousette changed the base branch from codex/ci-sqlite-fetch-fallback to sync/upstream-1.1.1 July 15, 2026 07:56
@marcus-pousette
marcus-pousette force-pushed the fix/close-failed-open-handle branch from 2655c59 to d7a1e3c Compare July 15, 2026 07:56
@marcus-pousette
marcus-pousette changed the base branch from sync/upstream-1.1.1 to master July 15, 2026 16:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant