Skip to content

fix(telemetry): wait for background exporter threads on client shutdown #2273

Description

@dan-petty

Problem Description

OTelTelemetryClient shutdown does not wait for background worker threads to exit.
The executor calls shutdown with wait=False.
The worker threads continue to run after client shutdown and after tracer reset.
In test runs, the remaining threads make HTTP requests to the loopback OpenTelemetry port 4318 during subsequent tests.
The test harness loopback guard detects these unexpected connections and fails innocent tests.

Reproduction Steps

  1. Create an OTelTelemetryClient instance with enabled=True.
  2. Submit an asynchronous export task with _send_payload.
  3. Call client.shutdown() while the export runs.
  4. Observe that devops-otel threads remain alive after shutdown() returns.
  5. In tests, the next test fails when the background thread connects to port 4318.

Expected vs Actual Behavior

Expected behavior: OTelTelemetryClient.shutdown() waits for all executor worker threads to terminate and marks the client disabled.
Actual behavior: client.shutdown() returns immediately with wait=False, leaving active worker threads running in the background.

Environment Diagnostics

  • DevOps CLI Version: 0.5.1
  • Python Version: 3.14.7
  • OS & Architecture: Linux x86_64
  • Execution Environment: GitHub Actions CI

Logs, Traces, or Terminal Output

ERROR tests/test_finding_repetition_compression.py::test_finding_collapses_consecutive_duplicate_lines - Failed: network edge reached without a fake — Connected to a loopback port no socket in this test process binds or reached an unfaked edge: ::1:4318 (devops-otel_0), 127.0.0.1:4318 (devops-otel_0), ::1:4318 (devops-otel_0), ::1:4318 (devops-otel_1), 127.0.0.1:4318 (devops-otel_1), 127.0.0.1:4318 (devops-otel_0). Fake the service at its edge, or refuse it through `refusing_port`.

Activity

  1. added
    source/agent
    type/bug
    on Oct 26, 2026
  2. dan-petty commented on Oct 26, 2026

    @dan-petty
    OwnerAuthor

    Intake placed this item to the backlog: intake puts every new item in the backlog. A person plans the milestones on the board.

    • Type: type/bug. The candidate describes a bug where client shutdown does not wait for background threads.
    • Priority: P1-High. The issue causes test failures due to unexpected network connections after shutdown.
    • Value: High. Fixing this improves test reliability and prevents false negatives in CI.
    • Effort: Medium. Requires modifying the shutdown method to wait for threads, which is a moderate change.
    • Related: test(cli): tests wait for a background thread with one generous bound, not a 1-second deadline, so they pass under load #1664, which asks for a different change. Both items deal with background threads and test stability, but the candidate focuses on client shutdown and the shortlist item on thread waiting in tests.
  3. added a commit that references this issue on Oct 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    source/agenttype/bug

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions