Repository navigation
test(examples): reap echo subprocess cleanly in test_echo_thin_waist (fixes #1541) - #1542
Merged
acul71 merged 1 commit intoSep 14, 2026
Conversation
…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
approved these changes
Sep 14, 2026
acul71
left a comment
Collaborator
There was a problem hiding this comment.
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_pathremoved; misleading "Trio primitives" note corrected - Valid
newsfragments/1541.internal.rst(ends with newline);Fixes #1541linked - 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::ResourceWarningwith no ResourceWarnings
Non-blocking nits (optional follow-ups)
- Early
proc.stdout is Nonepath stillterminate()s withoutwait()/close (practically unreachable withPIPE) - Comment mentions SIGTERM/SIGKILL; on Windows these map to
TerminateProcess— prefer terminate/kill wording
Merge readiness: Approve / squash-merge.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1541.
Problem
tests/examples/test_echo_thin_waist.pytears down the echo subprocess withterminate()thenkill()— noproc.wait(), and it never closesproc.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 unraisableResourceWarning(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::ResourceWarningemitsunclosed file <TextIOWrapper fd=13>(the never-closedproc.stdout).Fix
Reap the child cleanly in the
finally:terminate()→wait(timeout=5)→ escalate tokill()+wait()only if it does not exit → thenclose()the stdout pipe. Also dropped the misleading "Trio primitives" note (the test issubprocess+time) and the unusedmonkeypatch/tmp_pathfixtures — 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).tests/examples/— this is the onlysubprocess.Popentest, so no other demos teardown needs the same fix. ruff/format clean.