Skip to content

fix: preserve task stop channel during close#10

Merged
besnow merged 1 commit into
dev_newfrom
codex/create-minimal-fix-pr-for-task-close
May 16, 2026
Merged

fix: preserve task stop channel during close#10
besnow merged 1 commit into
dev_newfrom
codex/create-minimal-fix-pr-for-task-close

Conversation

@besnow
Copy link
Copy Markdown
Owner

@besnow besnow commented May 16, 2026

Motivation

  • Fix a race in Task.Close() where close(t.stop) followed by t.stop = nil could make the worker goroutine observe a nil t.stop after an Execute() return and lose the stop signal.
  • Preserve the existing duplicate-close safety while ensuring the worker listens on the original stop channel created in Start().

Description

  • Capture the channel created in Start() into a local variable with stop := t.stop immediately after t.stop = make(chan struct{}).
  • Change the worker goroutine select to listen on the local stop instead of t.stop (case <-stop:).
  • On Execute() error paths, under t.access lock, only close(stop) and set t.stop = nil when t.running && t.stop == stop to avoid double-close races.
  • Keep the existing Close() implementation unchanged.

Testing

  • Ran gofmt -w common/task/task.go which formatted the file successfully.
  • Ran go test ./... and the test suite completed with all tests passing.
  • Ran go build ./... and the project built successfully.

Codex Task

@besnow besnow merged commit 9516d3d into dev_new May 16, 2026
23 checks passed
@besnow besnow deleted the codex/create-minimal-fix-pr-for-task-close branch May 16, 2026 06:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant