Skip to content

fix: reject duplicate database opens - #319

Open
huytdps13400 wants to merge 1 commit into
margelo:mainfrom
huytdps13400:fix/306-atomic-duplicate-open
Open

fix: reject duplicate database opens#319
huytdps13400 wants to merge 1 commit into
margelo:mainfrom
huytdps13400:fix/306-atomic-duplicate-open

Conversation

@huytdps13400

Copy link
Copy Markdown

Summary

  • reject duplicate database names in the native registry before calling sqlite3_open_v2
  • preserve the existing connection when a session tries to reopen the same name from another location
  • keep newly opened handles under RAII ownership until registry insertion succeeds
  • close partial SQLite handles when sqlite3_open_v2 fails
  • cover both the public session API and direct NitroSQLite.native.open() path

The current connection identity remains dbName. Opening the same filename from a different location is therefore rejected explicitly instead of silently rerouting the first connection.

Closes #306.

TDD evidence

RED on main:

  • the session duplicate test threw from the JS queue only after native state had already been overwritten; the original connection then failed with no such table: ConnectionMarker
  • the direct native duplicate test received no error

GREEN: both focused tests pass against the rebuilt iOS app, and the original connection still returns its marker row.

Verification

  • focused iOS harness: 2 duplicate-open tests passed
  • full iOS unit harness: 34/34 passed
  • iOS TypeORM harness: 1/1 passed
  • iOS sqlite-vec harness: 35/35 passed
  • iOS example app build: succeeded
  • Android :react-native-nitro-sqlite:assembleDebug: succeeded for all configured ABIs
  • bun typecheck
  • bun lint
  • bun sqlite build
  • Prettier and clang-format checks for changed files
  • git diff --check
  • no dependency or lockfile changes

Existing test-runner limitation

bun sqlite test --runInBand exits during Jest configuration before collecting tests because React Native 0.85 moved its preset to @react-native/jest-preset. This is reproducible on unchanged main; the native harness suites above exercise the changed behavior.

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.

Opening the same database name twice overwrites the native connection before validation

1 participant