Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PROF-9136] Fix rare remote configuration worker thread leak #3519

Merged
merged 4 commits into from
Mar 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions lib/datadog/core/remote/worker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ def initialize(interval:, &block)
@thr = nil

@starting = false
@stopping = false
@started = false
@stopped = false

@interval = interval
raise ArgumentError, 'can not initialize a worker without a block' unless block
Expand All @@ -24,6 +24,11 @@ def start

acquire_lock

if @stopped
Datadog.logger.debug('remote worker: refusing to restart after previous stop')
return
end

return if @starting || @started

@starting = true
Expand All @@ -46,8 +51,6 @@ def stop

acquire_lock

@stopping = true

thread = @thr

if thread
Expand All @@ -56,8 +59,8 @@ def stop
end

@started = false
@stopping = false
@thr = nil
@stopped = true

Datadog.logger.debug { 'remote worker stopped' }
ensure
Expand Down
10 changes: 10 additions & 0 deletions spec/datadog/core/remote/worker_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,16 @@

expect(worker.instance_variable_get(:@thr).thread_variable_get(:fork_safe)).to be true
end

it 'does not restart the worker after being stopped once' do
worker.start
expect(worker.instance_variable_get(:@started)).to be true

worker.stop

worker.start
expect(worker.instance_variable_get(:@started)).to be false
end
end

describe '#stop' do
Expand Down
Loading