Repository navigation
Close the writer a previous JS runtime left open before opening - #3
Merged
Merged
Conversation
…before opening its own When the JS runtime reloads inside the same process, nitro-sqlite's native registry keeps the previous runtime's writer. nitro's open() registers a new handle under the same name without closing the old one, so a transaction the old runtime had in flight can stay open on the leaked handle and hold the write lock, and the new runtime's writes fail as "database is locked". openNitroConnection now closes a writer registered under the name by a previous runtime, the way openReader already reclaims the reader. When nothing is registered the close throws, which is swallowed. A reopen within one runtime is unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01J5R4szy5V6TVSutrikAztt
claude
Bot
force-pushed
the
claude/reclaim-stale-writer-on-reload
branch
from
October 28, 2026 20:21
c9ef77a to
f12b42b
Compare
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01J5R4szy5V6TVSutrikAztt
sleeper-luke
marked this pull request as ready for review
October 28, 2026 20:44
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Requested via Slack thread
Before: When the JS runtime reloads inside the same process, react-native-nitro-sqlite's native connection registry keeps the previous runtime's writer open. Opening the same database again registers a second handle under that name without closing the first, so a transaction the old runtime had in flight can stay open and hold the write lock, and the new runtime's writes fail with
database is locked.After: Opening a database first closes any writer a previous runtime left registered under that name. A reopen within one runtime is unchanged.
How: A new
reclaimStaleWriter(name)callsNitroSQLite.native.close(name)inside a try/catch, the same wayopenReaderalready reclaims a stale reader.openNitroConnectioncalls it aftercloseNitroConnectionand beforeopen, and only when this runtime's own map does not already hold the name. When nothing is registered, the close throws and the error is swallowed.Limits: Statements already in flight on the old handle can still resolve to the new one; fully fixing that needs a change in native nitro-sqlite.
Tests: Three new cases in
src/nitro/nitro_connection.test.ts; it andsrc/tests/define_sqlite_store.test.tspass in both the dev and prod jest configs.🤖 Generated with Claude Code
https://claude.ai/code/session_01J5R4szy5V6TVSutrikAztt