Repository navigation
Conversation
EnsureDaemon reads dataDir/daemon.lock to find a live daemon. When that lock is absent or stale but the config's admin_port is already held by a DIFFERENT ghosthost instance (e.g. one started against a different --config/data_dir, sharing the same default ports), EnsureDaemon would spawn a duplicate daemon that can only lose the bind race and die before writing a lockfile -- then poll the full hardcoded 10s window before reporting the generic "daemon unreachable", indistinguishable from a genuinely dead daemon. Detect the port conflict with a direct TCP probe before spawning, and report it immediately with the actionable cause instead.
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
EnsureDaemondecides whether a daemon is already running by reading<data_dir>/daemon.lock. When that lock is absent or stale, but theconfig's
admin_portis already held by a different runningghosthost instance (e.g. one started against a different
--config/data_dir, sharing the same default ports 8750/8751), theCLI would spawn a duplicate daemon that can only lose the bind race
and die before ever writing a lockfile. The CLI then polls the full
hardcoded 10-second readiness window before giving up with the generic
daemon unreachable-- a message indistinguishable from a genuinelydead daemon, even though a live daemon was answering on that port the
whole time.
This is the root cause of a live incident where
ghosthost --json listreliably took ~10.07s to reportdaemon unreachable, eventhough a raw TCP connect and
curlagainst the same admin portanswered in ~13ms: the CLI was resolving its config from the invoking
user's default config path (no
--configflag passed), which pointedat a different
data_dirthan the one the actually-running daemon(started via
--config /etc/...) was using.Change
EnsureDaemonnow does a short direct TCP probe of127.0.0.1:<admin_port>before spawning, whenever the lockfile read fails. If something is
already listening there, it fails immediately with a message naming
the real, actionable condition instead of spawning a doomed duplicate
and waiting out the full 10s.
Test plan
go build ./...go vet ./...go test ./...(all packages green)TestEnsureDaemon_PortInUseWithoutLock_FailsFastInsteadOfPolling:binds a real listener, calls
EnsureDaemonagainst an emptydata_dirwith that port, and asserts the call fails in wellunder the old 10s window with an "already in use" message.
TestEnsureDaemon_RefusesToSpawnTestBinarystill passes withthe new
adminPortparameter (passed as0, preserving priorno-conflict-check behavior for that path).