Skip to content

Comments

ThreadPool concurrency refactoring (#2220)#3

Open
MitchLewis930 wants to merge 1 commit intopr_053_beforefrom
pr_053_after
Open

ThreadPool concurrency refactoring (#2220)#3
MitchLewis930 wants to merge 1 commit intopr_053_beforefrom
pr_053_after

Conversation

@MitchLewis930
Copy link

@MitchLewis930 MitchLewis930 commented Jan 30, 2026

PR_053


Note

Medium Risk
Touches core thread-pool synchronization and shutdown/trim behavior, which can impact request handling and termination under load; changes are localized but concurrency-sensitive.

Overview
Refactors Puma::ThreadPool’s concurrency control by introducing with_mutex (allowing safe nested locking) and switching key operations (backlog, enqueue, capacity waiting, trim/reap, shutdown) to use it.

Adjusts worker lifecycle semantics: startup now waits for worker readiness when creating the minimum threads; trim only requests exits when there are truly free threads; and shutdown drives worker exits by setting @trim_requested = @spawned and broadcasting, with workers decrementing counters and exiting immediately when trimming.

Reworks test_thread_pool.rb to avoid timing-based races by using a MutexPool test helper that batches work and waits for completion, adds a dedicated thread-name assertion, and adds a new startup waiting assertion. History.md notes the ThreadPool concurrency fixes/refactor.

Written by Cursor Bugbot for commit b16d8cb. This will update automatically on new commits. Configure here.

- Wait for threads to enter waiting loop on ThreadPool startup
- Simplify #spawn_thread inner threadpool loop
- Refactor TestThreadPool to make tests faster and more stable

Co-authored-by: Nate Berkopec <nate.berkopec@gmail.com>
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.

2 participants