-
Notifications
You must be signed in to change notification settings - Fork 373
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
Puma warning log #3203
Comments
Hey @pbstriker38, thanks for reaching out! So... this one is a bit awkward/annoying. Mixing threads and processes using fork is often not a great idea, because (among others) the threads will (usually) not be carried over to the forked processes. I believe this is why puma issues that warning when it detects background threads. In the specific case of ddtrace, the above is not a problem: ddtrace automatically detects the fork operation and restarts its threads, so that's fine. But... puma doesn't really know about that... which is the awkward/annoying part. One way of avoiding this is to use puma's |
Good to know. Should there maybe be some documentation somewhere that mentions this? |
Very reasonable ask! I'm thinking it could be added to the "Known issues and suggested configurations" section of our docs. I'll leave this issue open until I open a PR for it (may take a few days, a bit tight ATM!) :) |
Actually now that I got back to this, I spotted in the puma code that there's actually a way to mark threads as fork safe, which is much better! So I've opened #3279 and in the future puma will not show this warning for ddtrace threads 🎉 |
**What does this PR do?** This PR applies to all relevant ddtrace threads a pattern pioneered by rails: set the `:fork_safe` thread variable to indicate that it's OK if ddtrace threads are started before a Ruby app calls fork. **Motivation:** This PR fixes the issue reported in DataDog#3203. The puma webserver in clustering mode has a check where it will warn when it detects that threads were started before the webserver has fork'd the child processes, see: https://github.com/puma/puma/blob/32e011ab9e029c757823efb068358ed255fb7ef4/lib/puma/cluster.rb#L353-L359 This is not a problem for ddtrace (as discussed in DataDog#3203), but the warning is annoying. While looking into the issue again today, I spotted that actually there's a way to tell puma that a thread is fine and is it's not a problem if it's started before the webserver has fork'd: puma checks if the thread has a `:fork_safe` thread-variable set to `true`. **Additional Notes:** We have a bunch of places in ddtrace where we create threads... I briefly played with the idea of creating a superclass of all ddtrace Threads, but decided to not get into a bigger refactoring for such a small issue. Maybe next time...? **How to test the change?** Test coverage included. Furthermore, you can try running a Ruby webapp in puma before/after the change to confirm the warning is gone. Fixes DataDog#3203
Current behaviour
Puma logs a warning that it has detected threads starting when the app boots
Expected behaviour
ddtrace should not be starting threads during app boot
Steps to reproduce
start puma with workers and
preload_app!
Environment
Datadog.configure ...
):The text was updated successfully, but these errors were encountered: