Skip to content

Fix race condition - #4

Open
dmthong181096 wants to merge 2 commits into
mmccl5:mainfrom
dmthong181096:fix-race-condition
Open

Fix race condition#4
dmthong181096 wants to merge 2 commits into
mmccl5:mainfrom
dmthong181096:fix-race-condition

Conversation

@dmthong181096

Copy link
Copy Markdown

This PR resolves the race conditions and data races reported in #1 when multiple tasks are run concurrently and their states/metadata are accessed or updated.

Changes:

  • Task Field Encapsulation: Unexported all mutable fields of Task (state, err, metadata, history, startedAt, finishedAt) to prevent direct, unsafe concurrent reads/writes from other goroutines.
  • Thread-Safe Accessors: Added synchronized getters/setters (using sync.RWMutex) for all encapsulated fields.
  • Atomic Transitions: Created helper methods (Start(), Complete(), and Fail(err)) to guarantee atomic transitions of task states, start/finish times, and history updates.
  • Runner Refactoring: Updated Runner.Run() to use these thread-safe helper methods instead of locking and modifying fields inline.

Verified that all tests compile and pass successfully, including parallel execution checks.

@dmthong181096

Copy link
Copy Markdown
Author

/claim #1

@opirebot

opirebot Bot commented Jun 13, 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.

1 participant