Skip to content

Commit

Permalink
synchronize a critical section for script_compiled tracepoint
Browse files Browse the repository at this point in the history
  • Loading branch information
anmarchenko committed Nov 22, 2024
1 parent fd23ba8 commit 7c4e422
Showing 1 changed file with 17 additions and 11 deletions.
28 changes: 17 additions & 11 deletions lib/datadog/ci/contrib/instrumentation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,25 +35,30 @@ def self.auto_instrument
return
end

# note that `Kernel.require` might be called from a different thread, so
# there is a possibility of concurrent execution of this tracepoint
mutex = Mutex.new
script_compiled_tracepoint = TracePoint.new(:script_compiled) do |tp|
all_patched = true

auto_instrumented_integrations.each do |integration|
next if integration.patched?
mutex.synchronize do
auto_instrumented_integrations.each do |integration|
next if integration.patched?

all_patched = false
next unless integration.loaded?
all_patched = false
next unless integration.loaded?

auto_configure_datadog
auto_configure_datadog

Datadog.logger.debug("#{integration.class} is loaded")
patch_integration(integration)
end
Datadog.logger.debug("#{integration.class} is loaded")
patch_integration(integration)
end

if all_patched
Datadog.logger.debug("All expected integrations are patched, disabling the script_compiled tracepoint")
if all_patched
Datadog.logger.debug("All expected integrations are patched, disabling the script_compiled tracepoint")

tp.disable
tp.disable
end
end
end
script_compiled_tracepoint.enable
Expand Down Expand Up @@ -152,6 +157,7 @@ def self.auto_configure_datadog
end
end

# This is not thread safe, it is synchronized by the caller in the tracepoint
def self.configure_once
@configure_once ||= Datadog::Core::Utils::OnlyOnce.new
end
Expand Down

0 comments on commit 7c4e422

Please sign in to comment.