evanphx/puma — Issue #38: Trimming in thread pool can result in requests hanging
Author: bporterfield
Created: 2012-02-04 20:01:31+00:00
State: open

With default AutoTrim settings, there is potential for requests to get stuck waiting on an available worker:

1. A long-running request is made, adding work to Queue and spawning a worker thread. There are now more than `min` workers alive.
2. The autotrim thread wakes up and, seeing threads that could be trimmed, adds a `Trim` to the Queue.
3. Second request is made while the first request is still working. New worker thread is spawned because there are no threads waiting on the Queue. Work is added to Queue.
4. Newly spawned worker thread pops `Trim` off of Queue, and promptly kills itself
5. Second request is still in Queue, but there is only 1 worker thread now, and it's still busy with the first request. Second request now hangs until first request completes (or another request comes in, spawning new thread).