Repository navigation
Set during_sample around the worker's final internal-thread sample - #6448
Conversation
`thread_context_collector_profiler_internal_thread_done` documents "Assumption 1: When called while the profiler is active, `during_sample` MUST be set", but `release_gvl_and_run_sampling_trigger_loop` called it bare. The profiler is still active at that point: `disable_hooks` and the `active_sampler_instance_state = NULL` reset only run after `rb_protect` returns in `_native_sampling_loop`. So `on_newobj_event` and `on_gc_event` can still fire and would observe `during_sample` unset while we sample the worker thread's own `sampling_buffer`. Route the call through `_native_profiler_internal_thread_done`, the other caller of the same function, which already wraps it in `during_sample_enter` + `rb_ensure(..., during_sample_exit_ensure)`. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
✅ All CI checks and tests passed. 🎉 All green!🧪 All tests passed 🎯 Code Coverage (details) 🔗 Commit SHA: 87a6c70 | Docs | View more details | Give us feedback! |
BenchmarksBenchmark execution time: 2026-10-08 15:26:17 Comparing candidate commit 87a6c70 in PR branch Found 0 performance improvements and 0 performance regressions! Performance is the same for 52 metrics, 0 unstable metrics.
|
ivoanjo
left a comment
There was a problem hiding this comment.
👍 Ah very elegant! It's one of those "obvious in retrospect, but I didn't see it when I was working on it". Thanks for the fix
thread_context_collector_profiler_internal_thread_donedocuments "Assumption 1: When called while the profiler is active,during_sampleMUST be set", butrelease_gvl_and_run_sampling_trigger_loopcalled it bare.The profiler is still active at that point:
disable_hooksand theactive_sampler_instance_state = NULLreset only run afterrb_protectreturns in_native_sampling_loop. Soon_newobj_eventandon_gc_eventcan still fire and would observeduring_sampleunset while we sample the worker thread's ownsampling_buffer.Route the call through
_native_profiler_internal_thread_done, the other caller of the same function, which already wraps it induring_sample_enter+rb_ensure(..., during_sample_exit_ensure).What does this PR do?
Motivation:
Change log entry
Additional Notes:
How to test the change?