Skip to content

parametric: bump library client SIGTERM grace to drain gRPC/OTLP threads#7009

Open
mabdinur wants to merge 1 commit into
mainfrom
munir/parametric-container-exit-diagnostics
Open

parametric: bump library client SIGTERM grace to drain gRPC/OTLP threads#7009
mabdinur wants to merge 1 commit into
mainfrom
munir/parametric-container-exit-diagnostics

Conversation

@mabdinur
Copy link
Copy Markdown
Contributor

@mabdinur mabdinur commented May 22, 2026

Problem

Rare (~1/1000) parametric flake where a test client container (e.g. python-test-client-*) starts successfully then exits ~0.6s later. The failure surfaces as Timeout of 60 seconds exceeded waiting for HTTP server to start because the framework's poll loop treats status == exited the same as "not ready yet" and keeps retrying. The flake is most often observed in OTel logs/metrics tests, which is where ddtrace's grpc integration patch and the OTLP exporter background threads are most active.

Example: dd-trace-py run 26044048099, job 76563345401.

Cause

docker_run was calling container.stop(timeout=1) for every container. 1s is enough for the test agent (no state to drain) but not for parametric library clients: ddtrace + OTLP exporter + gRPC patch hold background threads that bind host ports. SIGKILLing them mid-shutdown leaves those host ports in TIME_WAIT, which collides with the next test on the same xdist worker (which reuses the port allocation 4500 + worker_id).

Fix

Parameterise docker_run with a stop_timeout argument (default 1s — keeps existing behaviour for the test agent and any other zero-state fixtures) and pass stop_timeout=5 from the parametric library client only.

# utils/docker_fixtures/_core.py
def docker_run(..., stop_timeout: int = 1) -> ...:
    ...
    container.stop(timeout=stop_timeout)

# utils/docker_fixtures/_test_clients/_test_client_parametric.py
docker_run(..., stop_timeout=5)

Test plan

  • 5 sequential local runs of the target test: passed in 6.21s / 6.19s / 6.22s / 6.39s / 6.28s — within the prior baseline of ~6.5s. The new 5s cap only activates when the client actually fails to drain on SIGTERM.
  • Verified via tests.log: healthy python-test-client-* stop took ~454ms; ddapm-test-agent-* stop took ~1.5s. No regression on the happy path.
  • ./format.sh clean (mypy, ruff, yamllint, shellcheck).

@mabdinur mabdinur requested a review from a team as a code owner May 22, 2026 17:43
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 22, 2026

CODEOWNERS have been resolved as:

utils/docker_fixtures/_core.py                                          @DataDog/system-tests-core
utils/docker_fixtures/_test_clients/_test_client_parametric.py          @DataDog/system-tests-core

The previous ``container.stop(timeout=1)`` SIGKILLed parametric library clients
after 1s. Under healthy conditions clients exit in well under that, but the rare
~1/1000 OTel logs/metrics flake (manifesting as the next test's container
starting then exiting ~0.6s later) was consistent with mid-shutdown SIGKILLs
leaving ddtrace/OTLP/gRPC background threads holding host ports, which then
collide when the next test on the same xdist worker reuses the port allocation.

This change parameterises ``docker_run`` with a ``stop_timeout`` argument
(defaulting to 1s) and bumps it to 5s only for the parametric library client.
The test agent fixture is unaffected and keeps the 1s cap, so the targeted
``test_otel_logs.py::Test_FR11_Telemetry::test_telemetry_exporter_configurations``
stays at the baseline ~6.2s per run locally; the larger cap only bites in the
rare path where the client actually fails to drain on SIGTERM.

Co-authored-by: Cursor <cursoragent@cursor.com>
@mabdinur mabdinur force-pushed the munir/parametric-container-exit-diagnostics branch from d37757d to 812c6b4 Compare May 22, 2026 17:53
@mabdinur mabdinur changed the title parametric: diagnose container-exit flakes instead of waiting 60s parametric: bump library client SIGTERM grace to drain gRPC/OTLP threads May 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant