needed to make this safe for forks from non-main threads #212
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.
If a process happens to fork from a non-main thread (as happens e.g. in Puma's
fork_worker
mode) the term_on_timeout counter effectively disappears; whichever thread calls.fork
becomesThread.main
in the child process, losing the parent'sThread.main
storage. There are a few alternative solutions available: make this a real global (makes people feel icky but that's really what the code is doing) or adding a_fork
hook (only practical on recent Rubies or with ActiveSupport required), but the simplest method is to move the||= 0
initialization code prior to the request-time code that expects it.Happy to put up a PR with the alternate methods if you'd prefer, please lmk.
(the
test_helper
change is required for tests to work at all on my local; lots of failures for undefined Rack::Builder otherwise)