-
Notifications
You must be signed in to change notification settings - Fork 18
Spool down threads when exiting #10
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
Open
jjb
wants to merge
11
commits into
patrickxb:master
Choose a base branch
from
jjb:spool-down-threads-when-exiting
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
As of May 2017, successful submissions to stathat do not return a body: https://blog.stathat.com/2017/05/05/bandwidth.html This changes the code and tests to accommodate this new behavior. - the success code is now 200, not 204, so all 200s are considered successful - because there is no body, we no longer check for resp.msg == "ok" - oddly, failures return a "status: 500" in their body, but still have a 200 success code. I don't know if this is desired behavior or a bug, and I don't know how long this has been the case. i have written to StatHat support about it. so, we still parse for a code in the body and let it take precedent
- consistent use of {} for one-line blocks
- use do..end for more complicated block
While experimenting with the behavior of
StatHat::Reporter.instance.finish in master, I experienced
this message
No live threads left. Deadlock?
And a stack trace every time. The cause was because
we call join on the threads, all of which are waiting,
via Queue#pop, for a new item to come from the queue.
I found that the best way to solve this is to close the Queue
before killing the threads. In going about this and reading the docs,
I found that the status of the Queue could be used to coordinate the threads,
which means there is no longer a need for the standalone synchronization
Mutex.
The cherry on top of this refactoring sundae is that Queue#pop
will immediately return nil when the Queue has been closed,
allowing us to use this return value as the condition
for continuing the loop.
I'm guessing that
if th && th.alive?
was an attempt to accommodate the error that this change solves,
and regardless I feel those checks won't be needed or useful,
so I removed it.
- Waits 5 seconds to allow remaining queue to be cleared - Prints warning message if processing stops before queue is finished - Invokes existing signal trap behavior if there is any - Doesn't need to check for default system signal behavior and invoke exit, because we only are trapping EXIT. If we were trapping INT or TERM, we would need to invoke exit. https://stackoverflow.com/questions/49393648/
82e57c8 to
8da65b0
Compare
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
note: this is based on #9, so that should be merged first. Then this can be rebased and look tidier.
This PR achieves two things.
So, it solves the problem described here: http://www.stathat.com/manual/code/ruby
and clarified to me in a support ticket...
It's also good behavior to have in the general case such as in a web server, which might also lose some items in the queue
n.b. each thread is given 5 seconds to shut down, serially (as opposed to the previous infinite time). If we want to give all threads 5 (or whatever) seconds to shut down from the start of stop_pool to guarantee that the overall time is fixed, we can use an approach like this.
let me know what you think!