fix(pool): fix race condition with small pool sizes #83
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.
This pull request includes several changes to improve the testing process, optimize concurrency handling, and enhance buffer management. The most important changes include modifying test commands, refining worker pool dispatch logic, and adjusting buffer synchronization mechanisms.
Testing Improvements:
.github/workflows/main.yml
: Updated theTest
job to runmake test-ci
instead ofmake test
for CI-specific test configurations.Makefile
: Addedtest-ci
target with specific configurations for CI, and adjusted thetest
target to run tests with a shorter timeout and without counting.Worker Pool Enhancements:
pool.go
: IntroducedPERSISTENT_WORKER_COUNT
to ensure a minimum number of workers are always running while the dispatcher is running, addeddispatcherRunning
mutex to synchronize task dispatching, and refined worker start logic to prevent deadlocks. [1] [2] [3] [4] [5]Buffer Management Optimization:
internal/linkedbuffer/linkedbuffer.go
: Replacedsync.RWMutex
withsync.Mutex
for theLinkedBuffer
struct to simplify locking mechanisms, and adjusted theRead
method to use a single lock for better synchronization. [1] [2]Minor Code Refinements:
group_test.go
: Simplified the creation ofResultPool
andGroup
instances in tests.internal/dispatcher/dispatcher.go
: Removed unnecessary reset of thebatch
slice in therun
method.