Skip to content

Fix service process state data race - #75

Open
yaroslavvoloshchuk-codaio wants to merge 1 commit into
hermeticbuild:masterfrom
yaroslavvoloshchuk-codaio:agent/fix-service-process-state-race
Open

yaroslavvoloshchuk-codaio wants to merge 1 commit into
hermeticbuild:masterfrom
yaroslavvoloshchuk-codaio:agent/fix-service-process-state-race

Conversation

@yaroslavvoloshchuk-codaio

@yaroslavvoloshchuk-codaio yaroslavvoloshchuk-codaio commented Jul 19, 2026

Copy link
Copy Markdown

Summary

  • snapshot exec.Cmd.ProcessState under ServiceInstance's existing mutex after Cmd.Wait completes
  • route service process-state reads through the synchronized snapshot
  • add a Linux race-detector regression test in the existing tests workspace

Why

Cmd.Wait writes Cmd.ProcessState while Runner.StopAll and health checks may read it concurrently. The Go race detector reports that unsynchronized access in #71.

The snapshot preserves the existing ProcessState() API and is reset when a service command is reinitialized.

Regression test

The test uses target-local -no-pie because rules_go race mode requires external linking and the registered hermetic LLVM toolchain hits golang/go#76825: the linker probe drops required hermetic flags, misses -no-pie, and then rejects Go's position-dependent objects under PIE semantics. This flag affects only the Linux race-regression target.

Validation

  • before the fix, the focused test reproduced the Cmd.Wait / ProcessState() race under go test -race
  • GOWORK=/tmp/rules-itest-issue71-go.work go test -race -vet=off ./process_state_race -run '^TestProcessStateAccessIsSynchronized$' -count=1
  • bazel build //runner/...
  • exact-head full workflow run at 557bbc529ee1ab166322bd7990a5c4f73cad2cd4
    • Ubuntu: 43/43 tests passed; the new race target passed in 3.0s
    • Windows: 37 tests passed and six platform-incompatible tests, including the Linux-only race target, were skipped

Fixes #71.

@yaroslavvoloshchuk-codaio
yaroslavvoloshchuk-codaio force-pushed the agent/fix-service-process-state-race branch from 246486c to 557bbc5 Compare July 19, 2026 21:23
@yaroslavvoloshchuk-codaio
yaroslavvoloshchuk-codaio marked this pull request as ready for review July 19, 2026 22:47

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 557bbc529e

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread runner/runner.go
instance.waitErrFn = sync.OnceValue(func() error {
res := cmd.Wait()
instance.SetDone()
instance.setProcessState(cmd.ProcessState)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Do not leave ProcessState nil while WaitDelay is pending

For services whose child has already been reaped by the background Wait but Cmd.Wait is still waiting for copied stdout/stderr to finish or for the 50ms WaitDelay (for example, an exited service with a descendant holding stdout open), killGroup in StopWithSignal can return ESRCH and StopAll immediately records serviceInstance.ProcessState(). Since the snapshot is not assigned until after cmd.Wait() returns here, StopAll can return a nil state, and cmd/svcinit/main.go dereferences it when printing state.UserTime()/SystemTime(). Previously the direct cmd.ProcessState read was populated as soon as Process.Wait reaped the child, before WaitDelay, so this shutdown path still had a state.

Useful? React with 👍 / 👎.

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.

data race

1 participant