Revert "[NO-TICKET] Profiling: Clean up logic for tracking time spent in GC"#6012
Conversation
|
Thank you for updating Change log entry section 👏 Visited at: 2026-07-09 07:29:43 UTC |
🎉 All green!🧪 All tests passed 🎯 Code Coverage (details) 🔗 Commit SHA: 51d0677 | Docs | Datadog PR Page | Give us feedback! |
BenchmarksBenchmark execution time: 2026-07-09 07:55:04 Comparing candidate commit 51d0677 in PR branch Found 0 performance improvements and 0 performance regressions! Performance is the same for 48 metrics, 1 unstable metrics.
|
…try 2 **What does this PR do?** This PR is a second attempt at #6006 ; the first time got reverted in #6012 as we were seeing flaky failures. From DataDog/ruby-guild#314: ``` W, [2026-07-08T16:58:22.863694 #11835] WARN -- datadog: [datadog] CpuAndWallTimeWorker thread error. Operation: "rescued_sample_from_postponed_job" Cause: RuntimeError: BUG: Unexpected sample during GC (thread_id=11835 (10200), gc_tracking.cpu_time_at_start_ns=2802579244, gc_tracking.wall_time_at_start_ns=729604100602, monotonic_wall_time_now_ns=729890337067) Location: /__w/dd-trace-rb/dd-trace-rb/lib/datadog/profiling/collectors/idle_sampling_helper.rb:42:in 'Datadog::Profiling::Collectors::IdleSamplingHelper._native_idle_sampling_loop' W, [2026-07-08T16:58:22.863821 #11835] WARN -- datadog: [datadog] Failed to send telemetry before components initialization or within components lifecycle records garbage collection cycles (FAILED - 3) marks the new thread as fork-safe does not create a second thread if start is called again with allocation profiling enabled /__w/dd-trace-rb/dd-trace-rb/spec/datadog/profiling/collectors/cpu_and_wall_time_worker_spec.rb:43: [BUG] Datadog Ruby profiler detected callback nested inside sample. Please report this at https://github.com/datadog/dd-trace-rb/blob/master/CONTRIBUTING.md#found-a-bug ruby 4.0.1 (2026-01-13 revision e04267a14b) +PRISM [x86_64-linux] ``` (The "callback nested inside sample" happens because some of our tests have strict assertions that things like object allocations can't happen, and they were failing when trying to raise that `RunntimeError: BUG: Unexpected sample during GC` as well) The problem we were seeing was due to the `#on_gc_start` specs never clearing the "thread is in GC" state and thus this state was leaking to other tests which then would trigger the assertion we added. The fix is to make sure we don't leave such leftover state; in the future #5960 is a more holistic solution to this whole "leftover state between profiler instances" problem. I recommend reviewing this PR commit-by-commit. **Motivation:** The original cleanup is useful so we definitely want to keep it! **Additional Notes:** ``` bundle exec rspec './spec/datadog/profiling/collectors/cpu_and_wall_time_worker_spec.rb[1:2:12:1,1:2:12:2,1:2:13,1:2:15:1,1:2:16,1:2:18:1,1:2:18:2:1,1:2:20:1,1:7:1]' './spec/datadog/profiling/collectors/thread_context_spec.rb[1:3:2:1]' --seed 32922 ``` is one way of reproducing the issue. **How to test the change?** We should see a green CI and no flakiness.
Reverts #6006
We've been seeing some failures in tests caused by this, reverting until we can fix as we're in no rush to ship this one.
Change log entry
None.