-
Notifications
You must be signed in to change notification settings - Fork 375
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
Mark ddtrace threads as fork-safe #3279
Conversation
**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 #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 #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 #3203
Codecov ReportAttention:
Additional details and impacted files@@ Coverage Diff @@
## master #3279 +/- ##
==========================================
- Coverage 98.23% 98.22% -0.01%
==========================================
Files 1253 1253
Lines 72393 72418 +25
Branches 3393 3397 +4
==========================================
+ Hits 71112 71133 +21
- Misses 1281 1285 +4 ☔ View full report in Codecov by Sentry. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you drop a link to the relevant puma code section somewhere in our code base in a comment?
Done in e430e78 :) |
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 #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 #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 totrue
.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.
For Datadog employees:
credentials of any kind, I've requested a review from
@DataDog/security-design-and-guidance
.Fixes #3203