fix(cli)(sphere-sdk#247): refuse CLI when a sphere daemon holds the OrbitDB lock#28
Merged
Merged
Conversation
…lock The daemon parks the event loop forever with OrbitDB / Helia open; LevelDB takes a POSIX advisory file lock (fcntl(F_SETLK)) on <dataDir>/orbitdb/<dbAddress>/_index/LOCK and on <dataDir>/datastore/LOCK. A sibling CLI in the same dataDir hits LEVEL_LOCKED -> 'Database is not open', and the bounded retry from sphere-sdk PR #246 can never succeed (the contention isn't transient). This short-term gate detects the live-daemon case in getSphere() and exits with EX_TEMPFAIL, telling the operator to 'sphere daemon stop' first. Skipped when our own PID owns the PID file (daemon-start calling back into getSphere is the legitimate owner). Bypassed for daemon stop/status (which don't go through getSphere). The proper fix is a daemon-as-broker IPC surface (sphere-sdk #247 long-term: Unix domain socket at <dataDir>/.sphere-cli/daemon.sock, RemoteOrbitDbAdapter mirroring the OrbitDbAdapter interface). Until then, this stops the script-level cascade observed at §C.4 in manual-test-full-recovery.sh. Exports readPidFile and isDaemonProcessAlive from daemon.ts so legacy-cli.ts can reuse them without duplication.
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.
Summary
Short-term mitigation for the §C.4 "Database is not open" failure observed in `manual-test-full-recovery.sh` (unicity-sphere/sphere-sdk#247).
The daemon parks the event loop forever with OrbitDB / Helia open; LevelDB takes a POSIX advisory file lock (`fcntl(F_SETLK)`) on `/orbitdb//_index/LOCK` and on `/datastore/LOCK`. A sibling CLI in the same dataDir hits `LEVEL_LOCKED` → `Database is not open`, and the bounded retry from sphere-sdk PR #246 can never succeed (the contention isn't transient).
This gate detects the live-daemon case in `getSphere()` and exits with `EX_TEMPFAIL` (75), telling the operator to `sphere daemon stop` first. Skipped when our own PID owns the PID file (`daemon start` calling back into `getSphere` is the legitimate owner). Bypassed for `daemon stop`/`status` (which don't go through `getSphere`).
The proper long-term fix is a daemon-as-broker IPC surface (sphere-sdk#247 follow-up: Unix domain socket at `/.sphere-cli/daemon.sock` + RemoteOrbitDbAdapter mirroring the OrbitDbAdapter interface, so CLI commands talk to the running daemon instead of opening OrbitDB directly).
Changes
Test plan
Companion
Stacks with sphere-sdk `fix/issue-247-residuals` (which also updates the manual-test script to stop+start the daemons around §C.4).