fix(daemon): daemon stop reports a failed stop for a daemon that exits just before SIGTERM

Open Beginner friendly
#180 1 comment 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
68/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Quiet
Tech stack
go
Domain
cli

Research direction

Start in internal/daemon/stop.go, in stopTargets, where the error from stopSignal is appended to the joined error. The POSIX sender is sendStop in internal/daemon/stop_posix.go. Decide whether an os.ErrProcessDone result counts as stopped or is skipped, then handle it with errors.Is. Done when a test that injects os.ErrProcessDone through the stopSignal seam shows no error from daemon stop.

Written by the indexing model from the issue text.

Description

bug priority:low spec-needed

Problem

stopTargets (internal/daemon/stop.go) checks each record with isStale, and then sends SIGTERM through stopSignal. On POSIX that is sendStop (internal/daemon/stop_posix.go): os.FindProcess(pid), then proc.Signal(syscall.SIGTERM).

A daemon can exit between the isStale check and the signal. proc.Signal then returns os.ErrProcessDone ("os: process already finished"), and stopTargets adds it to the joined error:

if err := stopSignal(rec.PID); err != nil {
	errs = append(errs, fmt.Errorf("stopping pid %d: %w", rec.PID, err))
	continue
}

So codegraph daemon stop exits 1 with stopping pid N: os: process already finished, although the daemon is gone, which is what the user asked for. With #179, a stop that stopped nothing and failed prints nothing on stdout, so the user sees only that error.

Evidence

  • A scratch program in the suite review of #179 showed that SIGTERM to an exited pid returns os.ErrProcessDone.
  • The race was not reproduced through the command itself. The window between isStale and the signal is short.

Possible direction

  • In stopTargets, handle errors.Is(err, os.ErrProcessDone) without adding an error.
  • Decide whether such a record counts as stopped (the process is gone, so stopped pid N is true) or is skipped like a stale record.
  • Add a test through the stopSignal seam that returns os.ErrProcessDone.

Found by the silent-failure reviewer in the suite review of #179 (finding QUAL-4, PLAUSIBLE). The code predates #179.

🤖 Generated with Claude Code

https://claude.ai/code/session_01XFrTgTHsJM948TTYmCDjP5

Dominant language
Go
Stars
0
Forks
0
Avg merge
5h 16m
Merged PRs (30d)
107

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from seanb4t/codegraph-go

All issues in seanb4t/codegraph-go

Similar issues

More Go issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.