Skip to content

Terminate generated child processes when Wave test and example timeouts expire #507

Closed

Description

@LunaStev

Problem and local reproduction

A test timeout can stop wavec while its generated program continues running. This can leave CPU work, listening sockets or temporary-file writes active after the runner reports a timeout.

At e204bbebbbede0086fbb670d43a65b9cf38f0231:

  • tools/check_wave_corpus.py::run_std_examples launches wavec run with subprocess.run(..., timeout=...).
  • tools/run_tests.py::run_and_classify uses the same direct-child timeout pattern.
  • wavec run itself launches the generated executable as a child (src/cli.rs).

I reproduced the lifecycle defect on Linux by calling the actual run_std_examples helper against a temporary fake compiler. The fake compiler starts a child that waits 1.5 seconds and writes a marker, then itself waits 10 seconds. With a 0.4-second runner timeout, the runner reports RUN TIMEOUT, but the marker is written afterward. The reproducer uses no network or LLVM and the child exits on its own after writing the marker.

A minimal fake compiler body is:

import subprocess, sys, time
subprocess.Popen(
    [sys.executable, "-c", "import time,pathlib; time.sleep(1.5); pathlib.Path('child-survived').write_text('alive')"],
    stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL,
)
time.sleep(10)

Run it through the corpus helper with an isolated temporary root containing one examples/std/*.wave source, then check for the marker after the timeout. Give the fake compiler an executable wrapper appropriate for the host.

Scope and acceptance

  • Timeouts terminate and reap the launched compiler/program tree, including generated descendants, using host-appropriate process supervision.
  • Cover the corpus/example runner and end-to-end runner, including server-case cleanup where applicable.
  • Only terminate processes started for the current test; never kill by broad executable name.
  • Preserve timeout classification and useful captured stdout/stderr.
  • Add fake-process regression tests proving a delayed child side effect cannot occur after timeout cleanup.
  • Verify Linux and Windows behavior; distinguish cancellation from normal program failure.

Related: #354 covers corpus-runner unit tests, while #356 concerns a fixed inter-test delay. This is a separate process-lifecycle bug. It is not marked good first issue because reliable process-tree cleanup differs by OS.

Activity

  1. added
    bug
    help wanted
    needs testing
    cross-platform
    on Sep 7, 2026
  2. LunaStev commented on Nov 3, 2026

    @LunaStev
    MemberAuthor

    Current-master reproduction in the Rust process owner: escaped session survives timeout

    Audited canonical master e1f8effd195b6339c3979b1e091e63c25f1da983 on Linux amd64 with checkout-built Wave 0.0.1-alpha-dev, matching std, Rust 1.89.0, Cargo jobs=2 and LLVM 21.1.8. The master SHA was rechecked before registration. The historical Python runner has been retired by #1071; the same descendant-cleanup acceptance requirement now applies to the shared native process owner.

    The Unix owner sends SIGKILL to its owned process group, but a launched descendant can start a new session and leave that group. If that descendant inherits captured stdout/stderr, the subsequent collector joins also wait beyond the command deadline.

    Starting points: Owner::stop, process group setup and unbounded collector joins after stopping.

    Executed Linux reproduction; all child processes finish on their own within a few seconds and no remote service is needed:

    from pathlib import Path
    import subprocess
    import sys
    import tempfile
    import time
    
    root = Path.cwd()
    with tempfile.TemporaryDirectory(prefix="wave-timeout-session-") as temporary:
        marker = Path(temporary) / "survived"
        child = (
            "import time,pathlib;"
            "time.sleep(2);"
            f"pathlib.Path({str(marker)!r}).write_text('survived');"
            "print('child complete',flush=True)"
        )
        parent = (
            "import subprocess,sys,time;"
            f"subprocess.Popen([sys.executable,'-c',{child!r}],start_new_session=True);"
            "time.sleep(8)"
        )
        start = time.monotonic()
        result = subprocess.run([
            str(root / "target/debug/wave-tools"),
            "exec", "--timeout", "1", "--capture", "--",
            sys.executable, "-c", parent,
        ], capture_output=True, text=True, timeout=6)
        print("elapsed:", time.monotonic() - start)
        print("exit:", result.returncode)
        print("stdout:", result.stdout.strip())
        print("stderr:", result.stderr.strip())
        print("descendant marker exists:", marker.exists())

    Observed:

    elapsed: approximately 2.22 seconds
    exit: 1
    stdout: child complete
    stderr: wave-tools: timeout
    descendant marker exists: True
    

    The tool reports timeout, but the detached descendant completes its delayed side effect after the one-second limit. The retained output pipe makes collector completion depend on that surviving process rather than the requested deadline.

    Remaining scope:

    • Terminate and reap the descendants owned by this tool even across session/process-group changes, using a host-appropriate strategy.
    • Bound stdin/stdout/stderr collector shutdown after timeout/cancellation; a surviving inherited pipe must not cause indefinite joins.
    • Keep timeout classification, useful captured diagnostics and normal successful execution intact.
    • Test escaped-session descendants and inherited pipes; never kill unrelated processes by executable name.
    • Verify Windows supervision separately. This reproduction only establishes current native Linux behavior.

    This belongs to #507's existing process-tree lifecycle contract, not a new Python migration issue. Existing issue state, labels and assignees are retained. No implementation or CI run is included.

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

    bugcross-platformhelp wantedneeds testing

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions