fix: resolve race conditions in concurrent task execution - #8
Open
TonyWei041209 wants to merge 1 commit into
Open
fix: resolve race conditions in concurrent task execution#8TonyWei041209 wants to merge 1 commit into
TonyWei041209 wants to merge 1 commit into
Conversation
Author
|
Hi @mmccl5, this PR has been open for about 10 hours with all checks passing and no merge conflicts. Just a friendly ping to see if you'd have a moment to review and merge. Thanks! |
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.
Description
Fixes the race condition in concurrent task execution. When
Runner.Run()runs tasks concurrently in separate goroutines, direct access totask.State,task.Err, etc. causes data races with concurrent readers (e.g., tests callingGetState()).Changes
task.go: AddedTransitionTo(state, error)method that atomically sets state, error, history, and timestamps (StartedAt/FinishedAt) under the mutex. This replaces manual lock-write-unlock patterns inRunner.Run().runner.go: Replaced all direct field access (task.mu.Lock(),task.State = ...,task.Err = ...) with calls totask.TransitionTo(). The newStatus()method provides a thread-safe snapshot of all task states.runner_test.go: Updated tests to use public API (GetState(),GetErr()). Added stress tests:TestRunner_Run_ConcurrentWrites: 50 tasks with concurrent metadata readsTestRunner_Run_Timeout: context deadline testTestRunner_Run_Status: Status() output validationTestRunner_Run_Historical: State history correctnessTestTask_ConcurrentAccessors: 20 goroutines reading + 1 writing concurrentlyTestRunner_Run_MetadataRace: 3 concurrent readers + 50 tasks with metadatago.mod: Added module definition (was missing).Verification
All tests pass with
-raceflag:Closes #1