Skip to content

Fix race condition in concurrent task execution - #9

Open
singularitycurse26-svg wants to merge 1 commit into
mmccl5:mainfrom
singularitycurse26-svg:fix/1-race-condition
Open

Fix race condition in concurrent task execution#9
singularitycurse26-svg wants to merge 1 commit into
mmccl5:mainfrom
singularitycurse26-svg:fix/1-race-condition

Conversation

@singularitycurse26-svg

Copy link
Copy Markdown

Fixes #1

Changes

workspace/task/runner.go

  • Replaced all direct field access (task.State, task.Err, task.History, task.StartedAt, task.FinishedAt) with thread-safe setter methods (SetState, SetErr, SetStartedAt, SetFinishedAt)
  • Eliminated manual task.mu.Lock()/Unlock() blocks in favor of encapsulated methods
  • State transitions are now atomic through the existing SetState method which handles locking internally

workspace/task/task.go

  • Added SetStartedAt and SetFinishedAt methods for thread-safe write access to time fields

workspace/task/runner_test.go

  • Fixed TestRunner_Run to use GetState() instead of direct t1.State field access (race condition in test itself)
  • Added TestRunner_Run_StressWithCancel — 100 concurrent tasks with mid-execution cancellation, concurrent metadata reads/writes, and state checks. Verifies go test -race passes cleanly.

Acceptance Criteria Met

  • All data races eliminated: no direct concurrent field access
  • go test -race ./... passes with zero data race warnings
  • Task state transitions (Pending -> Running -> Completed/Failed) are atomic via SetState with mutex
  • Concurrent writes to shared maps/structs synchronized via existing mutex-protected getters/setters
  • Context cancellation handled gracefully with proper state transition to Failed

/claim #1

@opirebot

opirebot Bot commented Jul 20, 2026

Copy link
Copy Markdown

👀 We've notified the reward creators here.
Make sure your payment account is ready to receive the payment for your hard work 💪

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.

🎯 Fix Race Condition in Concurrent Task Execution

1 participant