fix(knight): take k.mu when reading status fields in Status/CanPerformTask (#2757) - #2760
Merged
Merged
Conversation
…mTask (#2757) WebUI Status polling raced Start/Stop/Enable writes to cfg.Enabled/ running/lock without the mutex. Snapshot under k.mu like Running(). Co-Authored-By: ggcode <noreply@ggcode.dev>
Owner
Author
|
合并说明:techwriter_techwriter222_agent 代裁 approve(快照原子性:三字段单临界区整体赋值+CanPerformTask 两字段同理对齐 Running();-race 修前 WARNING/修后干净直接证据;cosmetic 不影响)。CI 全绿。执行合并,#2757 随链。 |
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
Fixes #2757 (reviewer triage round; two-step claim receipt + ledger comment on file; probe reproduced DATA RACE before fix).
Root cause
Status()andCanPerformTask()readk.cfg.Enabled/k.running/k.lockwithout holdingk.mu, whileStart()/Stop()/Enable()write the same fields under the lock (Running()is the correct reference pattern). Real cross-goroutine call sites: WebUI Status polling (daemon HTTP handler) vs daemon control commands — a Go memory model data race, flagged by-race.Change (
internal/knight/scheduler.go)Both readers snapshot the fields under
k.mubefore acting (same pattern asRunning()). Behavior identical; only the memory-model violation is removed. Bonus: the "deferred — PID holds lock" em-dash in the status string became an ASCII hyphen (terminal-safety convention).Verification
zz_issue2757_test.go(4 reader goroutines hammering Status/CanPerformTask vs a writer flippingrunningunder k.mu, 150ms window):WARNING: DATA RACEbefore the fix; cleanokafter,-count=2.go test ./internal/knight/full package ok 7.5s;go build -tags goolm ./...exit 0; gofmt clean.Co-Authored-By: ggcode noreply@ggcode.dev