Skip to content

test(examples): reap echo subprocess cleanly in test_echo_thin_waist (fixes #1541) - #1542

Merged
acul71 merged 1 commit into
libp2p:mainfrom
yashksaini-coder:fix/echo-thin-waist-teardown-1541
Sep 14, 2026
Merged

acul71 merged 1 commit into
libp2p:mainfrom
yashksaini-coder:fix/echo-thin-waist-teardown-1541

Conversation

@yashksaini-coder

Copy link
Copy Markdown
Contributor

Fixes #1541.

Problem

tests/examples/test_echo_thin_waist.py tears down the echo subprocess with terminate() then kill() — no proc.wait(), and it never closes proc.stdout. That leaks the stdout pipe (and, on Windows, the child echo server's listener socket, since SIGKILL gives it no chance to close gracefully).

Since #1533 enabled the global filterwarnings = ["error::ResourceWarning"] guard, that leak turns into a failure — windows (3.12, demos) failed while pytest processed the unraisable ResourceWarning (aggravated by a Windows pytest-tracemalloc hook bug). It is unrelated to the PR it surfaced on (#1532 / ICE-Lite), as noted in #1541.

Reproduced on Linux too: pytest tests/examples/test_echo_thin_waist.py -W all::ResourceWarning emits unclosed file <TextIOWrapper fd=13> (the never-closed proc.stdout).

Fix

Reap the child cleanly in the finally: terminate() → wait(timeout=5) → escalate to kill() + wait() only if it does not exit → then close() the stdout pipe. Also dropped the misleading "Trio primitives" note (the test is subprocess + time) and the unused monkeypatch/tmp_path fixtures — both flagged in #1541.

Verification

  • pytest tests/examples/test_echo_thin_waist.py -W error::ResourceWarning → 1 passed (previously errored under the guard).
  • -W all::ResourceWarning → 0 ResourceWarnings (was leaking the pipe).
  • Swept tests/examples/ — this is the only subprocess.Popen test, so no other demos teardown needs the same fix. ruff/format clean.

…ixes libp2p#1541)

The teardown called terminate() then kill() without proc.wait() and never
closed proc.stdout, leaking the stdout pipe (and the child's listener socket on
Windows). Under the error::ResourceWarning CI guard (libp2p#1533) that failed
`windows (3.12, demos)` while pytest processed the unraisable warning.

Send SIGTERM, wait with a timeout, escalate to SIGKILL only if the child does
not exit, then close the read end of the pipe. Also drop the misleading "Trio
primitives" note and the unused monkeypatch/tmp_path fixtures.

Fixes libp2p#1541

@acul71 acul71 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approval

Ready to merge. Clean, focused fix for #1541 that matches the maintainer teardown guidance.

Verified

  • terminate() → wait(timeout=5) → kill() fallback → out_stream.close() correctly reaps the echo subprocess and closes the stdout pipe
  • Unused monkeypatch/tmp_path removed; misleading "Trio primitives" note corrected
  • Valid newsfragments/1541.internal.rst (ends with newline); Fixes #1541 linked
  • Branch in sync with main (0 behind / 1 ahead), no merge conflicts
  • CI fully green, including previously failing windows (3.12, demos)
  • Local targeted check: passes under -W error::ResourceWarning with no ResourceWarnings

Non-blocking nits (optional follow-ups)

  • Early proc.stdout is None path still terminate()s without wait()/close (practically unreachable with PIPE)
  • Comment mentions SIGTERM/SIGKILL; on Windows these map to TerminateProcess — prefer terminate/kill wording

Merge readiness: Approve / squash-merge.

@acul71
acul71 merged commit 6853ee5 into libp2p:main Sep 14, 2026
74 of 75 checks passed
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.

ci(windows): test_echo_thin_waist fails via unraisable ResourceWarning / tracemalloc (demos)

2 participants