From c06a2140c93c19e9e8403a27345d7483c38a0bda Mon Sep 17 00:00:00 2001 From: Andrey Marchenko Date: Fri, 28 Jun 2024 11:32:11 +0200 Subject: [PATCH 1/3] fix deadlock issue: don't flush_events in main thread when calling stop, override #work_pending? instead --- lib/datadog/core/telemetry/worker.rb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/datadog/core/telemetry/worker.rb b/lib/datadog/core/telemetry/worker.rb index f19a324704a..f4f65a5186f 100644 --- a/lib/datadog/core/telemetry/worker.rb +++ b/lib/datadog/core/telemetry/worker.rb @@ -52,8 +52,6 @@ def start def stop(force_stop = false, timeout = @shutdown_timeout) buffer.close if running? - flush_events(dequeue) if work_pending? - super end @@ -136,6 +134,10 @@ def dequeue buffer.pop end + def work_pending? + @run_loop || !buffer.empty? + end + def buffer_klass if Core::Environment::Ext::RUBY_ENGINE == 'ruby' Core::Buffer::CRuby From 6c5399b9389bc66e0016f9137975e18faf1b3f26 Mon Sep 17 00:00:00 2001 From: Andrey Marchenko Date: Fri, 28 Jun 2024 11:36:54 +0200 Subject: [PATCH 2/3] fix flaky test --- spec/datadog/core/telemetry/worker_spec.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/spec/datadog/core/telemetry/worker_spec.rb b/spec/datadog/core/telemetry/worker_spec.rb index e73fec0888e..bc88ad63b38 100644 --- a/spec/datadog/core/telemetry/worker_spec.rb +++ b/spec/datadog/core/telemetry/worker_spec.rb @@ -275,6 +275,8 @@ worker.start expect(worker).to receive(:flush_events).at_least(:once) + + worker.enqueue(Datadog::Core::Telemetry::Event::AppIntegrationsChange.new) worker.stop(true) end end From 5a06b583474b1536beede20c019b468a5e8c39ae Mon Sep 17 00:00:00 2001 From: Andrey Marchenko Date: Fri, 28 Jun 2024 11:54:00 +0200 Subject: [PATCH 3/3] use method instead of instance variable --- lib/datadog/core/telemetry/worker.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/datadog/core/telemetry/worker.rb b/lib/datadog/core/telemetry/worker.rb index f4f65a5186f..4ab562a99d6 100644 --- a/lib/datadog/core/telemetry/worker.rb +++ b/lib/datadog/core/telemetry/worker.rb @@ -135,7 +135,7 @@ def dequeue end def work_pending? - @run_loop || !buffer.empty? + run_loop? || !buffer.empty? end def buffer_klass