Skip to content

Commit 67d68aa

Browse files
committed
Wire fork safety into native transport via AtForkMonkeyPatch
Register a `:child` callback that calls `_native_after_fork_in_child` on the exporter to recreate the tokio runtime in forked child processes. Without this, the Rust runtime is dead after fork and subsequent send calls would hang or fail. The `AtForkMonkeyPatch` only supports `:child` stage, so `before_fork` and `after_fork_in_parent` are not called. The child path is the critical one: it creates a fresh runtime regardless of whether the parent was prepared.
1 parent f170f9e commit 67d68aa

1 file changed

Lines changed: 9 additions & 0 deletions

File tree

lib/datadog/tracing/transport/native.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,15 @@ def initialize(agent_settings:, logger: Datadog.logger)
7777
service: service,
7878
version: version
7979
)
80+
81+
# In forked child processes the tokio runtime is dead.
82+
# Recreate it so the exporter can send traces again.
83+
exporter = @exporter
84+
Core::Utils::AtForkMonkeyPatch.at_fork(:child) do
85+
exporter._native_after_fork_in_child
86+
rescue => e
87+
Datadog.logger.warn { "Native transport after-fork reset failed: #{e}" }
88+
end
8089
end
8190

8291
# Send a list of traces to the agent.

0 commit comments

Comments
 (0)