Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

needed to make this safe for forks from non-main threads #212

Merged

Conversation

toregeschliman
Copy link
Contributor

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 becomes Thread.main in the child process, losing the parent's Thread.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)

@toregeschliman toregeschliman changed the title needed to make this safe fork forks from non-main threads needed to make this safe for forks from non-main threads Dec 20, 2023
romanbsd added a commit to BioData/rack-timeout that referenced this pull request Mar 12, 2024
Copy link
Collaborator

@wuputah wuputah left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for the contribution!

@wuputah wuputah merged commit 5fc73d3 into zombocom:main May 15, 2024
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants