Skip to content

bug(ci): a single hanging test burns the 25-minute unit-suite budget — no --timeout despite pytest-timeout being installed #2019

Closed

Description

@dolho

Summary

backend-unit-test.yml installs pytest-timeout but never passes --timeout, so a single hanging test consumes the job's entire 25-minute budget. The job is then cancelled by timeout-minutes: 25, the JUnit upload step is skipped, and the failure surfaces as an opaque ##[error]The operation was canceled against whichever PR happened to be running.

It has now hit the base side — i.e. unmodified dev — so it is not branch-specific and can redden arbitrary PRs.

Evidence

Job Side/seed Duration Outcome
92259006786 (PR #1952) base, 67890 25m cancelled at 81%
92250694744 (PR #2010) head, 99999 25m15s cancelled at 96%

Sibling shards of the same commits finish in ~10m, so this is not general slowness. The logs show the suite stalling, not crawling — on the #1952 job there is a 3m37s gap between two progress lines with no output at all:

2026-08-05T09:30:42  ........................................ [ 79%]
2026-08-05T09:34:19  ........................................ [ 80%]
2026-08-05T09:35:34  ##[error]The operation was canceled.

That is the signature of one test blocking, not of a slow runner.

Why it is worse than a slow job

  1. No per-test attribution. The run dies without naming the test that hung, so each occurrence costs a manual log dig, and nothing accumulates toward finding the culprit.
  2. The artifact is lost. Upload JUnit XML has no if: always(), so on cancellation it never runs. diff-pytest-failures.py is deliberately fail-closed on a missing XML, which is correct — but it means one hang turns into a second, differently-worded failure on the regression diff job.
  3. It lands on innocent PRs. A base-side cancellation is a property of dev, not of the PR under test, but it is the PR that goes red.

Suggested fix

Pass a per-test timeout in the existing invocation — the plugin is already installed (tests/requirements-test.txt:4), so this is one flag:

python -m pytest unit/ -m "not slow" \
  --timeout=60 --timeout-method=thread \
  -p randomly --randomly-seed=${{ matrix.seed }} \
  ...

A hang then fails that test, by name, in 60s, the suite completes, the JUnit XML uploads, and the regression-diff job reports it as an ordinary new failure. The culprit becomes visible instead of inferred.

Worth adding if: always() to the upload step as well, so a partial XML still reaches the diff job rather than being silently absent.

--timeout-method=thread rather than the default signal method because parts of this suite run their own event loops; the signal method cannot interrupt a blocked C call, which is the case most likely to be at fault here.

Acceptance criteria

  • A hanging unit test fails by name rather than cancelling the job
  • The 25-minute job timeout stops being reachable through a single test
  • JUnit XML reaches the diff job even when the pytest step ends abnormally
  • The specific test(s) responsible for the two cancellations above are identified once the timeout makes them visible

Related

Activity

  1. added
    priority-p2
    type-bug
    theme-reliability
    on Aug 5, 2026
  2. dolho commented on Aug 5, 2026

    @dolho
    ContributorAuthor

    Correction to the issue body — this is not seed-specific, and I said so too early.

    Two more occurrences since filing, plus a re-run result that contradicts my original framing:

    Job Side/seed PR Duration
    92250694744 head, 99999 #2010 25m15s
    92259006786 base, 67890 #1952 25m
    92259640402 base, 67890 #1976 25m
    92263213170 head, 12345 #2018 25m16s

    So: all three seeds, both sides, four different PRs. I had written that the twice-hit base, seed 67890 shard implied a specific test ordering. That is wrong — the third and fourth occurrences are different seeds, and more decisively, re-running the exact same seed-67890 base job passed (#1952 is now green with no code change). Same ordering, different outcome, so ordering alone is not sufficient.

    What the evidence actually supports:

    • It is not general runner slowness. The fix(ci): give the nightly's merge check a common ancestor (#1941) #1952 log has a 3m37s gap with zero output between two progress lines (09:30:42 → 09:34:19). A slow runner produces evenly-spaced-but-slower dots; this is a stall.
    • It is timing-dependent, not deterministic — same seed passes on re-run. That points at something that usually returns fast and occasionally blocks: a socket/DNS call with a long default timeout, a lock, or a subprocess wait.
    • The two 09:30–09:40 occurrences were near-simultaneous on different PRs, consistent with a shared condition in the runner pool at that moment rather than anything in the code.

    None of this changes the fix, and it strengthens the case for it: with --timeout=60 --timeout-method=thread, an intermittent 3-minute block fails that test by name instead of consuming the 25-minute budget and dying anonymously. Right now every occurrence costs a manual log dig and yields no accumulating evidence about which test is responsible — which is exactly why I was able to guess wrong about the cause.

    --timeout-method=thread matters more given the stall shape: if the block is inside a C-level socket wait, the default signal method cannot interrupt it.

  3. dolho commented on Aug 5, 2026

    @dolho
    ContributorAuthor

    /claim

  4. added
    status-in-progress
    on Aug 5, 2026
  5. github-actions commented on Aug 5, 2026

    @github-actions

    Claimed by @dolho. Label status-in-progress added.

    Next steps:

    1. Create branch: feature/2019-<short-slug>
    2. Implement the feature
    3. Open a PR with Fixes #2019
  6. dolho commented on Aug 5, 2026

    @dolho
    ContributorAuthor

    Handled in #2021 — with both of my recommendations in this issue corrected, because measuring contradicted them.

    60s was wrong and would have caused an outage. Pulled the real durations from a green run's JUnit instead of guessing: test_start_agent_skip_inject's two retry cases legitimately run 60.62s and 60.57s (three real connection retries), then 39.9s and 26.6s in test_1083_result_callback. A 60s cap fails those two on every PR. And the cap has to survive the very runner variance this issue is about — a 2.5x-slow shard puts a 60.6s test near 150s — so it landed at 300s, which still converts a multi-minute stall into a named failure with ~5 of them fitting in the budget.

    thread was wrong too. I justified it here by saying SIGALRM cannot interrupt a blocked C call. That is the docs' caveat, not a fact about this suite, and I should have tested it before recommending it:

    E       Failed: Timeout (>10.0s) from pytest-timeout.
    1 failed in 10.21s     # socket.connect() to an unroutable address, --timeout-method=signal
    

    More importantly thread is the worse outcome even when it works: it dumps stacks and kills the process, so the run aborts, the JUnit is incomplete, and the diff job fails with no complete comparison — just a named culprit in a log. signal raises inside the test and the suite continues, so the diff job reports the hang as an ordinary new failure by name. The logs back that shape: #1952 kept progressing after its 3m37s gap, so these are stalls that release, not one permanent hang.

    Scope note: #2021 covers backend-unit-test.yml only. backend-unit-nightly.yml has the same 25-minute budget and wants the same two lines, but PR #1952 is open against that file — better applied there than shipped as a conflict.

  7. added
    status-in-dev
    and removed
    status-in-progress
    on Aug 6, 2026
  8. removed
    status-in-dev
    on Aug 17, 2026
  9. added a commit that references this issue on Sep 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

priority-p2theme-reliabilitytype-bug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions