mirror of
https://github.com/chenhg5/cc-connect.git
synced 2026-07-03 12:28:10 +08:00
Follow-up to #1436. The third call site in drainPendingMessages was modeled correctly in spirit (capture into local var before goroutine) but missed two details that #1436 applied to the first two sites: 1. The capture `as := state.agentSession` happened without holding state.mu, so the same race the PR set out to fix could still nil the field between the unlock above and the capture. 2. The Send goroutine did not have a defensive `if as == nil` check, unlike the other two sites; a nil capture would still panic when the goroutine ran. Also folds the existing nil/Alive check into the post-capture path so the gating uses the local copy (consistent with the new contract). No behavior change for the happy path; in the racy path the goroutine returns an error instead of dereferencing nil, which the existing error handling already covers. Verified locally: - go vet ./... clean - go build clean - go test -race ./core -run TestCUJ_H2_TwoPlatformsConcurrentNoBleed -count=10 PASS - go test ./core -run "Drain|Queue" PASS