Skip to content

fix(sidecar): enable test_ddog_sidecar_register_app on Windows (APMSP-2356)#1848

Draft
Leiyks wants to merge 28 commits intomainfrom
leiyks/fix-apmsp-2356-windows-pipe-race
Draft

fix(sidecar): enable test_ddog_sidecar_register_app on Windows (APMSP-2356)#1848
Leiyks wants to merge 28 commits intomainfrom
leiyks/fix-apmsp-2356-windows-pipe-race

Conversation

@Leiyks
Copy link
Copy Markdown
Contributor

@Leiyks Leiyks commented Apr 7, 2026

Problem

test_ddog_sidecar_register_app was suppressed on Windows with #[ignore] (APMSP-2356) because it was failing.

The test was already passing on Windows with the current windows.rs implementation — the #[ignore] annotation was simply never removed.

Fix

Remove the #[cfg_attr(target_os = "windows", ignore = "APMSP-2356 ...")] attribute from test_ddog_sidecar_register_app so the test runs and is validated in Windows CI.

Add the missing winbase, handleapi, and processthreadsapi winapi feature flags to datadog-sidecar/Cargo.toml to match the APIs already used in windows.rs (LocalFree, CloseHandle, OpenProcessToken, GetCurrentProcess).

@Leiyks Leiyks force-pushed the leiyks/fix-apmsp-2356-windows-pipe-race branch from 6bd5773 to ba5ba4b Compare April 7, 2026 15:16
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 7, 2026

Clippy Allow Annotation Report

Comparing clippy allow annotations between branches:

  • Base Branch: origin/main
  • PR Branch: origin/leiyks/fix-apmsp-2356-windows-pipe-race

Summary by Rule

Rule Base Branch PR Branch Change

Annotation Counts by File

File Base Branch PR Branch Change

Annotation Stats by Crate

Crate Base Branch PR Branch Change
clippy-annotation-reporter 5 5 No change (0%)
datadog-ffe-ffi 1 1 No change (0%)
datadog-ipc 21 21 No change (0%)
datadog-live-debugger 6 6 No change (0%)
datadog-live-debugger-ffi 10 10 No change (0%)
datadog-profiling-replayer 4 4 No change (0%)
datadog-remote-config 3 3 No change (0%)
datadog-sidecar 55 55 No change (0%)
libdd-common 10 10 No change (0%)
libdd-common-ffi 12 12 No change (0%)
libdd-data-pipeline 5 5 No change (0%)
libdd-ddsketch 2 2 No change (0%)
libdd-dogstatsd-client 1 1 No change (0%)
libdd-profiling 13 13 No change (0%)
libdd-telemetry 19 19 No change (0%)
libdd-tinybytes 4 4 No change (0%)
libdd-trace-normalization 2 2 No change (0%)
libdd-trace-obfuscation 8 8 No change (0%)
libdd-trace-utils 15 15 No change (0%)
Total 196 196 No change (0%)

About This Report

This report tracks Clippy allow annotations for specific rules, showing how they've changed in this PR. Decreasing the number of these annotations generally improves code quality.

@datadog-prod-us1-4

This comment has been minimized.

@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Apr 7, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 71.83%. Comparing base (d83038c) to head (daa6c92).
⚠️ Report is 7 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1848      +/-   ##
==========================================
+ Coverage   71.70%   71.83%   +0.13%     
==========================================
  Files         429      429              
  Lines       67916    68082     +166     
==========================================
+ Hits        48697    48905     +208     
+ Misses      19219    19177      -42     
Components Coverage Δ
libdd-crashtracker 66.15% <ø> (+0.11%) ⬆️
libdd-crashtracker-ffi 35.36% <ø> (+0.89%) ⬆️
libdd-alloc 98.77% <ø> (ø)
libdd-data-pipeline 86.23% <ø> (+0.08%) ⬆️
libdd-data-pipeline-ffi 72.95% <ø> (+0.44%) ⬆️
libdd-common 79.16% <ø> (ø)
libdd-common-ffi 73.87% <ø> (ø)
libdd-telemetry 65.98% <ø> (ø)
libdd-telemetry-ffi 16.75% <ø> (ø)
libdd-dogstatsd-client 82.64% <ø> (ø)
datadog-ipc 73.10% <ø> (ø)
libdd-profiling 81.62% <ø> (ø)
libdd-profiling-ffi 64.94% <ø> (ø)
datadog-sidecar 30.79% <ø> (+0.25%) ⬆️
datdog-sidecar-ffi 9.97% <ø> (+1.19%) ⬆️
spawn-worker 54.69% <ø> (ø)
libdd-tinybytes 93.16% <ø> (ø)
libdd-trace-normalization 81.71% <ø> (ø)
libdd-trace-obfuscation 87.24% <ø> (ø)
libdd-trace-protobuf 68.25% <ø> (ø)
libdd-trace-utils 89.24% <ø> (+0.52%) ⬆️
datadog-tracer-flare 86.88% <ø> (ø)
libdd-log 74.69% <ø> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@dd-octo-sts
Copy link
Copy Markdown
Contributor

dd-octo-sts bot commented Apr 7, 2026

Artifact Size Benchmark Report

aarch64-alpine-linux-musl
Artifact Baseline Commit Change
/aarch64-alpine-linux-musl/lib/libdatadog_profiling.so 7.63 MB 7.63 MB 0% (0 B) 👌
/aarch64-alpine-linux-musl/lib/libdatadog_profiling.a 83.25 MB 83.25 MB 0% (0 B) 👌
aarch64-unknown-linux-gnu
Artifact Baseline Commit Change
/aarch64-unknown-linux-gnu/lib/libdatadog_profiling.so 10.10 MB 10.10 MB 0% (0 B) 👌
/aarch64-unknown-linux-gnu/lib/libdatadog_profiling.a 99.29 MB 99.29 MB 0% (0 B) 👌
libdatadog-x64-windows
Artifact Baseline Commit Change
/libdatadog-x64-windows/debug/dynamic/datadog_profiling_ffi.dll 25.16 MB 25.16 MB 0% (0 B) 👌
/libdatadog-x64-windows/debug/dynamic/datadog_profiling_ffi.lib 78.21 KB 78.21 KB 0% (0 B) 👌
/libdatadog-x64-windows/debug/dynamic/datadog_profiling_ffi.pdb 184.22 MB 184.18 MB --.02% (-40.00 KB) 💪
/libdatadog-x64-windows/debug/static/datadog_profiling_ffi.lib 916.99 MB 916.99 MB 0% (0 B) 👌
/libdatadog-x64-windows/release/dynamic/datadog_profiling_ffi.dll 7.88 MB 7.88 MB 0% (0 B) 👌
/libdatadog-x64-windows/release/dynamic/datadog_profiling_ffi.lib 78.21 KB 78.21 KB 0% (0 B) 👌
/libdatadog-x64-windows/release/dynamic/datadog_profiling_ffi.pdb 23.64 MB 23.64 MB 0% (0 B) 👌
/libdatadog-x64-windows/release/static/datadog_profiling_ffi.lib 46.13 MB 46.13 MB 0% (0 B) 👌
libdatadog-x86-windows
Artifact Baseline Commit Change
/libdatadog-x86-windows/debug/dynamic/datadog_profiling_ffi.dll 21.63 MB 21.63 MB 0% (0 B) 👌
/libdatadog-x86-windows/debug/dynamic/datadog_profiling_ffi.lib 79.42 KB 79.42 KB 0% (0 B) 👌
/libdatadog-x86-windows/debug/dynamic/datadog_profiling_ffi.pdb 188.30 MB 188.32 MB +0% (+16.00 KB) 👌
/libdatadog-x86-windows/debug/static/datadog_profiling_ffi.lib 902.01 MB 902.01 MB 0% (0 B) 👌
/libdatadog-x86-windows/release/dynamic/datadog_profiling_ffi.dll 6.12 MB 6.12 MB 0% (0 B) 👌
/libdatadog-x86-windows/release/dynamic/datadog_profiling_ffi.lib 79.42 KB 79.42 KB 0% (0 B) 👌
/libdatadog-x86-windows/release/dynamic/datadog_profiling_ffi.pdb 25.31 MB 25.31 MB 0% (0 B) 👌
/libdatadog-x86-windows/release/static/datadog_profiling_ffi.lib 43.60 MB 43.60 MB 0% (0 B) 👌
x86_64-alpine-linux-musl
Artifact Baseline Commit Change
/x86_64-alpine-linux-musl/lib/libdatadog_profiling.a 74.38 MB 74.38 MB 0% (0 B) 👌
/x86_64-alpine-linux-musl/lib/libdatadog_profiling.so 8.51 MB 8.51 MB 0% (0 B) 👌
x86_64-unknown-linux-gnu
Artifact Baseline Commit Change
/x86_64-unknown-linux-gnu/lib/libdatadog_profiling.a 91.66 MB 91.66 MB 0% (0 B) 👌
/x86_64-unknown-linux-gnu/lib/libdatadog_profiling.so 10.18 MB 10.18 MB 0% (0 B) 👌

@Leiyks Leiyks changed the title fix(sidecar): retry connect on Windows to fix named-pipe startup race (APMSP-2356) fix(ipc): replace retry workaround with WaitNamedPipe + readiness signal (APMSP-2356) Apr 8, 2026
Leiyks added 9 commits April 13, 2026 16:50
…ipe IPC

On Windows, a named-pipe client's CreateFileA fails immediately if the
server has not yet called ConnectNamedPipe — there is no kernel-level
connection backlog as Unix domain sockets provide.  After daemonize()
returns the child process exists but its Tokio runtime may not have
entered the accept loop yet, causing test_ddog_sidecar_register_app to
fail intermittently.

Add connect_to_sidecar_with_retry() that retries the connection with
exponential back-off (1 ms → 100 ms cap, up to 20 attempts ≈ 1.9 s
total) when just_spawned is true.  On non-Windows platforms is_pipe_not_ready()
always returns false so the helper is a single-attempt no-op there.

Remove the APMSP-2356 ignore annotation from test_ddog_sidecar_register_app
so the fix is validated in CI.
Fix clippy::precedence warning in libdd-trace-utils/src/otlp_encoder/mapper.rs:
the shift operator binds tighter than bitwise OR, but explicit parentheses
make the intent unambiguous.
- Remove WouldBlock from is_pipe_not_ready: CreateFileA uses synchronous
  mode and only returns ERROR_FILE_NOT_FOUND (NotFound) or ERROR_PIPE_BUSY
  (ConnectionRefused); WouldBlock can never appear on this path. Add
  comments mapping Windows error codes to io::ErrorKind variants.
- Replace unreachable post-loop connect_to_server() call with
  unreachable!(): every loop iteration already returns via Ok, retry,
  or Err arm, making the trailing call dead code.
- Add "Safe to block" comment on std::thread::sleep to clarify it is
  called from synchronous FFI context, not from within a Tokio task.
Replace the exponential-backoff retry loop in start_or_connect_to_sidecar()
with two proper Windows-native fixes that address the root cause:

1. WaitNamedPipeA in SeqpacketConn::connect(): instead of immediately
   returning ConnectionRefused on ERROR_PIPE_BUSY, block up to 5 s for a
   pipe instance to become available, then retry CreateFileA.

2. Readiness signal via named Windows event: setup_daemon_process() creates
   a named manual-reset event (Local\dd-sidecar-ready-<PID>), passes its
   name to the child via DD_SIDECAR_READY_EVENT, and returns a ReadinessWaiter
   that blocks on WaitForSingleObject(30 s). The child calls
   signal_sidecar_ready() inside acquire_listener (Tokio runtime running,
   listener ready) before entering the accept loop. daemonize() calls the
   waiter after wait_spawn() so the parent cannot connect before the pipe
   is guaranteed to exist.

On Unix, domain sockets have a kernel-level connection backlog so neither
fix is needed; setup_daemon_process returns a no-op ReadinessWaiter.
The pointer→integer→pointer round-trip (event as usize / guard.0 as HANDLE)
creates a pointer with no provenance in Rust's strict provenance model, which
can produce ERROR_INVALID_HANDLE (os error 6) at runtime.

Store the HANDLE (*mut c_void) directly in OwnedEvent, eliminating all casts.
Add `unsafe impl Send` with a SAFETY comment explaining why cross-thread use
of a Windows HANDLE is valid.

Also explicitly declare the winapi features used by this module (synchapi,
handleapi, processthreadsapi) in Cargo.toml so they are guaranteed to be
linked regardless of transitive dependencies.

Fixes test_ddog_sidecar_register_app panicking with "Sidecar failed to signal
readiness: The handle is invalid. (os error 6)".
The CreateEventA/WaitForSingleObject cross-process signalling was
consistently returning WAIT_FAILED (ERROR_INVALID_HANDLE) in CI.
SeqpacketConn::connect already has a 30-second WaitNamedPipeA retry
loop that handles the child startup race naturally, so the named event
is redundant. Remove it along with the SPAWN_SEQ counter, OwnedEvent
RAII guard, and signal_sidecar_ready helper.
@Leiyks Leiyks force-pushed the leiyks/fix-apmsp-2356-windows-pipe-race branch from 485fe3a to a77297a Compare April 13, 2026 14:50
Leiyks added 4 commits April 13, 2026 17:13
The WaitNamedPipeA retry loop added in a previous commit was not needed
for the sidecar startup race: the pipe is created by the parent before
daemonize() is called, so CreateFileA succeeds as soon as the child
process starts (Windows queues the client connection before the server
calls ConnectNamedPipe). Restore the original single-call pattern that
returns ConnectionRefused on ERROR_PIPE_BUSY.
The comment referenced a WaitNamedPipeA retry loop in SeqpacketConn::connect
that no longer exists. Replace with the accurate explanation: the named pipe
is created by the parent before daemonize(), so the client connection succeeds
immediately — Windows queues it before ConnectNamedPipe is called.
…rn types

setup_daemon_process never needed to return a readiness callable — the
named pipe exists before the child is spawned and Windows queues client
connections at the kernel level. Revert entry.rs, unix.rs and windows.rs
to their origin/main signatures (io::Result<()> / Ok(())).
…mment

Revert cosmetic diff in start_or_connect_to_sidecar return statement and
restore the original "Ensure unique process names" comment in
setup_daemon_process on Windows.
@Leiyks Leiyks force-pushed the leiyks/fix-apmsp-2356-windows-pipe-race branch from 2c29f5d to b98b4f9 Compare April 13, 2026 16:08
@Leiyks Leiyks changed the title fix(ipc): replace retry workaround with WaitNamedPipe + readiness signal (APMSP-2356) fix(sidecar): enable test_ddog_sidecar_register_app on Windows (APMSP-2356) Apr 13, 2026
unix.rs and windows.rs were missing a blank line before Ok(()) in
setup_daemon_process, diverging from origin/main.
@Leiyks Leiyks force-pushed the leiyks/fix-apmsp-2356-windows-pipe-race branch from b98b4f9 to 64185b0 Compare April 14, 2026 11:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants