Skip to content

Prevent concurrent servers from sharing a data directory - #2423

Open
ymichael wants to merge 4 commits into
mainfrom
bb/investigate-thread-display-issue-thr_9bchdk89cn
Open

Prevent concurrent servers from sharing a data directory#2423
ymichael wants to merge 4 commits into
mainfrom
bb/investigate-thread-display-issue-thr_9bchdk89cn

Conversation

@ymichael

@ymichael ymichael commented Aug 25, 2026

Copy link
Copy Markdown
Collaborator

What was wrong

The server had no data-directory singleton lock. During overlapping dev restarts, a second server could open the same SQLite database before losing its port bind. Because in-flight provisioning context is process-local, startup recovery in that second process could treat a live starting thread as orphaned and emit a false thread_provisioning_failed event.

What changed

  • Extracted the host daemon robust lock implementation into a shared @bb/process-utils data-directory lock module, including stale-lock recovery and compromise handling.
  • Added a server.lock acquired before logger creation, initDb(), and startup recovery.
  • Let a recently crashed owner's lock age through the stale window during startup while still rejecting a lock refreshed by a live server before SQLite opens.
  • Made compromise re-acquisition timers non-owning so releasing the lock cannot pin a shutting-down process.
  • Kept synchronous exit cleanup armed until asynchronous unlock finishes.
  • Held server ownership until shutdown, with cleanup on both normal shutdown and startup failure.
  • Kept the host daemon on the same shared implementation through its existing wrapper without forwarding ignored options.
  • Wire changes: none. HOST_DAEMON_PROTOCOL_VERSION is unchanged.

How you verified

  • Added regressions for rejecting a live server before initDb(), reclaiming a fresh orphaned server lock, releasing ownership after startup failure, releasing during compromise re-acquisition, and retaining exit cleanup through asynchronous unlock.
  • Added shared lock tests for compromise re-acquisition, stale-lock recovery, and yielding to a live contender, plus host-daemon wrapper coverage.
  • pnpm exec turbo run test --filter=@bb/server --force — 2,037 tests passed.
  • pnpm exec turbo run test --filter=@bb/host-daemon --force — 557 tests passed.
  • pnpm exec turbo run test --filter=@bb/process-utils --force — 25 tests passed.
  • pnpm exec turbo run typecheck --filter=@bb/process-utils --filter=@bb/server --filter=@bb/host-daemon passed.
  • pnpm exec turbo run build --filter=@bb/server --filter=@bb/host-daemon passed.
  • node packages/plugin-sdk/scripts/check-npm-version-guard.mjs passed.

Related to #2190: prevents concurrent bb server access to the database directory, but does not resolve the WAL durability/reversion issue.

Fixes: no linked issue.

AGENT GENERATED

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