fix(prof) reset interrupt count when removing interrupt #3455
+6
−1
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.
Description
Move resetting the
REQUEST_LOCALS.interrupt_count
to0
fromrinit
torshutdown
or better: to the interrupt manager when we remove an interrupt. This fixes a tiny race condition:dd-trace-php/profiling/src/profiling/interrupts.rs
Lines 56 to 62 in 3456dec
RSHUTDOWN
MSHUTDOWN
gets called and PHP cleans up internal classes' static properties which could trigger a userland constructor (bug in PHP 8.0, fixed in >8.1) and we collect a sample and crash in the firstexecute_ex
because of the leaked interruptSo far we mitigated sampling bias (just collecting at the first opportunity in the new request because of the leaked interrupt) by initialising the
interrupt_count
with0
inRINIT
:dd-trace-php/profiling/src/lib.rs
Line 580 in 3456dec
Moving this to
RSHUTDOWN
makes sure it does not leak to whatever comes afterRSHUTDOWN
, also does not introduce any sampling bias and seems a cleaner approach.I can't think of any situation right now that could result in
REQUEST_LOCALS.interrupt_count
being not0
inRINIT
.Reviewer checklist