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 out_of_band hook never executed when multiple worker threads (clo… #2180
Fix out_of_band hook never executed when multiple worker threads (clo… #2180
Conversation
This approach makes a bit more sense as it's still truly OOB. Need to think about implementation... |
Rather than use the pipe to communicate intra-process, couldn't we use a condition variable to signal to a thread in the server to run the oob calls? |
Hey! Thanks for the feedback @nateberkopec. I'm not sure about the If you really want to implement it that way, can you please explain me how you would do it? For now, I implemented it using a boolean & a mutex. EDIT: I edited the PR description. |
I removed a now useless |
Oh awesome! Thanks for correcting me - as weird as this may sound coming from a current maintainer of Puma, I'm not an expert on the Mutex/CV classes (that code is almost entirely still Evan's). But it seemed to me like the checkpipe was unnecessary when the threadpool and the runner were always going to be in the same process - you figured it out. |
I'm wondering about how we could test this. |
I don't know either, it seems there were no tests at all for the OOB hook. |
Thanks for your contribution. #2218 has tests and is a little cleaner IMO, so I'm going to close this PR. |
Description
This is an alternative solution for #2177.
The other PR is #2178. The difference is that this PR keeps strictly the same behaviour as before (i.e. runs OOB hook only if all threads are free).
Issue description
C.F. #2177
Fix description
Here is the code responsible for executing the
out_of_band
hook:Due to how the function
wait_until_not_full
(in lib/puma/thread_pool.rb) works, namely:The condition
if busy_threads == 0
could never be satisfied if the number of worker threads was > 1. It could be satisfied if the worker finished its job before the call towait_until_not_full
, which is very unlikely because this function is called right after adding the client to the pool.This PR fixes this problem by giving a callback function to
ThreadPool.initialize
to signal theServer
when all worker threads are free (using the boolean variable@all_worker_threads_free
).Your checklist for this pull request
[changelog skip]
the pull request title.[ci skip]
to the title of the PR.#issue
" to the PR description or my commit messages.