Skip to content

test(support): time_limit's one-shot alarm can be swallowed and hang an xdist worker #1892

Closed

Description

@JarryShaw

tests/_support.time_limit (tests/_support.py:75) arms a single signal.alarm(seconds), and its handler raises TimeoutError exactly once. #1891 found that this one-shot pattern can be lost. A finaliser that runs the raise sends it to sys.unraisablehook, and an except OSError swallows it because TimeoutError is an OSError (Extractor.__del__ catches exactly that). Either way the body then runs until pytest-timeout's 900s backstop ends the xdist worker. That is what hung the #1428 deadline test (#1889).

time_limit has the same exposure: a lost raise turns a bounded test into a 15-minute worker crash with no traceback.

Fix: once it has fired, re-arm until the with block exits, as #1891 does for the generator's _deadline. The re-arm must not outlive the block, and the previous handler and pending alarm must still be restored. Add a test where a finaliser swallows the first raise, and check that it fails quickly without the fix.

Related: under xdist, pytest-timeout writes its stack dump to the worker's stdout, which is /dev/null. A hang like #1889's leaves only node down: Not properly terminated. Consider sending the dump somewhere the job log keeps, for example through faulthandler to stderr or a file the job uploads.

Activity

  1. added
    testPull requests that add or correct tests (test: subject prefix)
    pendingAccepted and unstarted - nobody is on it and nothing blocks it
    wipWork in flight - a covering PR is open or an agent is actively on it
    and removed
    pendingAccepted and unstarted - nobody is on it and nothing blocks it
    on Oct 17, 2026
  2. removed
    wipWork in flight - a covering PR is open or an agent is actively on it
    on Oct 17, 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

    testPull requests that add or correct tests (test: subject prefix)

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions