Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(pool): fix race condition with small pool sizes #83

Merged
merged 7 commits into from
Nov 13, 2024

Conversation

alitto
Copy link
Owner

@alitto alitto commented Nov 10, 2024

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 the Test job to run make test-ci instead of make test for CI-specific test configurations.
  • Makefile: Added test-ci target with specific configurations for CI, and adjusted the test target to run tests with a shorter timeout and without counting.

Worker Pool Enhancements:

  • pool.go: Introduced PERSISTENT_WORKER_COUNT to ensure a minimum number of workers are always running while the dispatcher is running, added dispatcherRunning 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: Replaced sync.RWMutex with sync.Mutex for the LinkedBuffer struct to simplify locking mechanisms, and adjusted the Read method to use a single lock for better synchronization. [1] [2]

Minor Code Refinements:

Copy link

codecov bot commented Nov 10, 2024

Codecov Report

Attention: Patch coverage is 97.72727% with 1 line in your changes missing coverage. Please review.

Project coverage is 96.10%. Comparing base (f1d2a44) to head (3880586).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
pool.go 97.61% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #83      +/-   ##
==========================================
+ Coverage   96.00%   96.10%   +0.09%     
==========================================
  Files          14       14              
  Lines         827      847      +20     
==========================================
+ Hits          794      814      +20     
  Misses         30       30              
  Partials        3        3              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@alitto alitto force-pushed the fix/AD/buffer-has-elements-len branch 7 times, most recently from 473622d to 3832cf8 Compare November 11, 2024 13:03
@alitto alitto force-pushed the fix/AD/buffer-has-elements-len branch from 3832cf8 to 7949c7b Compare November 11, 2024 13:13
@alitto alitto force-pushed the fix/AD/buffer-has-elements-len branch 4 times, most recently from cc66d7d to af893ef Compare November 13, 2024 11:25
@alitto alitto changed the title fix(linkedbuffer): fix bufferHasElements channel length fix(pool): fix race condition with small pool sizes Nov 13, 2024
@alitto alitto force-pushed the fix/AD/buffer-has-elements-len branch 3 times, most recently from 839e1aa to 14cf17a Compare November 13, 2024 12:03
@alitto alitto force-pushed the fix/AD/buffer-has-elements-len branch from 14cf17a to 3880586 Compare November 13, 2024 12:07
@alitto alitto merged commit 543ed3a into main Nov 13, 2024
9 checks passed
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