diff --git a/profiling/src/lib.rs b/profiling/src/lib.rs index f32b883e1c..7ef94bae7d 100644 --- a/profiling/src/lib.rs +++ b/profiling/src/lib.rs @@ -577,7 +577,6 @@ extern "C" fn rinit(_type: c_int, _module_number: c_int) -> ZendResult { let result = REQUEST_LOCALS.try_with_borrow_mut(|locals| { // SAFETY: we are in rinit on a PHP thread. locals.vm_interrupt_addr = unsafe { zend::datadog_php_profiling_vm_interrupt_addr() }; - locals.interrupt_count.store(0, Ordering::SeqCst); // SAFETY: We are after first rinit and before mshutdown. unsafe { diff --git a/profiling/src/profiling/interrupts.rs b/profiling/src/profiling/interrupts.rs index ab69b11034..bd1e32107e 100644 --- a/profiling/src/profiling/interrupts.rs +++ b/profiling/src/profiling/interrupts.rs @@ -46,6 +46,12 @@ impl InterruptManager { pub(super) fn remove_interrupt(&self, interrupt: VmInterrupt) { let mut vm_interrupts = self.vm_interrupts.lock().unwrap(); vm_interrupts.remove(&interrupt); + unsafe { + // Reset interrupt counter to prevent sampling during `mshutdown` (PHP 8.0 bug with + // userland destructors), but leave the interrupt flag unchanged as other extensions + // may have raised it. + (*interrupt.interrupt_count_ptr).store(0, Ordering::SeqCst); + } } #[inline]