Repository navigation
Conversation
runServer ran migrations, the server-import boot and the startup recovery sweep before anything stopped a second server on the same data directory. The server now takes an OS file lock on <data-dir>/server.lock first, waits up to 15 s for a restarting server to exit, and then fails with a clear message. The OS releases the lock when the process exits, also after a crash. Fixes get-bb#7360
alexburlis
added a commit
to alexburlis/omnyo
that referenced
this pull request
Nov 26, 2026
Record the upstream PRs, revisions, contributors, and Omnyo integration commits for merge d2a24ac in docs/upstream-credits.md. Original-PR: get-bb/bb#7663 Original-Commit: get-bb/bb@1737a03 Original-Author: rufi Original-PR: get-bb/bb#8055 Original-Commit: get-bb/bb@651ae20 Original-Author: Jake Lancaster Original-PR: get-bb/bb#8075 Original-Commit: get-bb/bb@511e1ed Original-Author: Jake Lancaster Original-Co-Author: Michael Yong Original-Co-Author: Claude Opus 5.5 Original-PR: get-bb/bb#8096 Original-Commit: get-bb/bb@775090b Original-Author: Michael Yong Original-Co-Author: Claude Opus 5.5 Original-PR: get-bb/bb#8145 Original-Commit: get-bb/bb@8de6711 Original-Commit: get-bb/bb@0d3db49 Original-Commit: get-bb/bb@92d3a76 Original-Commit: get-bb/bb@6705422 Original-Author: Michael Yong Original-Co-Author: Claude Opus 5.5 Original-PR: get-bb/bb#8171 Original-Commit: get-bb/bb@b56ed04 Original-Author: Jake Lancaster Original-PR: get-bb/bb#8238 Original-Commit: get-bb/bb@2a9a142 Original-Author: SawyerHood Original-PR: get-bb/bb#8247 Original-Commit: get-bb/bb@ba4ae22 Original-Author: Salem Original-Co-Author: Claude Opus 5.5 Original-PR: get-bb/bb#8259 Original-Commit: get-bb/bb@96f40a9 Original-Author: SawyerHood Original-PR: get-bb/bb#8263 Original-Commit: get-bb/bb@141e40a Original-Author: mk Original-PR: get-bb/bb#8266 Original-Commit: get-bb/bb@84e20e9 Original-Author: ILIA GOLUBEV
Contributor
|
This is an automated message. We have closed this pull request because it has been open for more than two weeks. |
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.
Human comments
What was wrong
runServerinapps/server/src/start-server.tshad no check for another server on the sameBB_DATA_DIRbefore it touched the database. A second server on the same data directory (for example on another port, or started without the launcher) raninitDb(migrations), the server-import boot andrunStartupRecoverySweepagainst the sharedbb.dbbefore anything stopped it. The sweep acts on state that it takes to be from a previous server process. The launcher guard from #5404 catches only a second server that answers/healthat the same URL (#7360, triage report).What changed
packages/config/src/file-lock.ts: a newacquireFileLock({ path, timeoutMs })takes the existing native lock (fs-native-extensions) and returns a release function.withFileLocknow uses it, with the same behavior.apps/server/src/services/system/data-dir-lock.ts:lockServerDataDirtakes<data-dir>/server.lockand keeps it until the process exits. It waits up to 15 s, so a server that the launcher restarts can wait for the previous process to exit. After that it throwsServerDataDirInUseError: "Another bb server is using the data directory ... Stop that server before starting another one on this directory."start-server.ts:runServertakes the lock first, beforerefuseInterruptedServerImportandinitDb.This uses the native lock that the server already loads for
managed-json-file, so there is no new dependency and no lockfile change. The OS releases the lock when the process exits, also after a crash orSIGKILL, so a stale lock cannot block a restart. The daemon'sproper-lockfilelock was not used, because its stale-lock detection is time-based and the server can stall for longer than its 10 s window (#6835).Behavior to note: if a second launcher starts on a data directory that is in use, its server exits with this error, and the launcher restarts it after its usual delay. Each attempt fails without touching the database.
No wire, CLI or documentation change.
How you verified
apps/server/test/system/data-dir-lock.test.ts: a second lock on the same directory fails withServerDataDirInUseError, and succeeds after the first is released.packages/config/test/file-lock.test.ts(lock held by a child process, released when the child dies) passes on the refactored code.pnpm exec turbo run typecheck lint test --filter=@bb/server --filter=@bb/config: server 4111 tests and config 102 tests pass.oxfmt --checkpasses on the changed files.Not checked: two real server processes on one data directory, and Windows (
LockFileExthroughfs-native-extensions).Fixes #7360