Skip to content

fix: close stdout/stderr pipes in AcpTransport.close()#83

Open
KuaaMU wants to merge 1 commit intomco-org:mainfrom
KuaaMU:fix/close-stdout-pipe-on-stop
Open

fix: close stdout/stderr pipes in AcpTransport.close()#83
KuaaMU wants to merge 1 commit intomco-org:mainfrom
KuaaMU:fix/close-stdout-pipe-on-stop

Conversation

@KuaaMU
Copy link
Copy Markdown

@KuaaMU KuaaMU commented Apr 30, 2026

Problem

AcpTransport.close() closes stdin and calls terminate()/wait(), but never closes the stdout (and stderr) pipes opened as subprocess.PIPE. The file descriptor leaks until GC, triggering ResourceWarning when running with -W error::ResourceWarning.

python3 -W error::ResourceWarning -m unittest tests/test_acp_transport.py
transport.py:269: ResourceWarning: unclosed file <_io.TextIOWrapper name=5 encoding='UTF-8'>
  self._process = None

Solution

Close stdout and stderr before terminate(), following the same try/except pattern used for stdin. Catch both OSError and ValueError to handle concurrent reader thread edge cases.

Reference: runtime/session/manager.py lines 54-57 uses the same cleanup pattern for daemon subprocesses.

Verification

python -W error::ResourceWarning -m unittest tests.test_acp_transport -v

All 13 tests pass. Two new tests added:

  • test_close_no_resource_warning — verifies no ResourceWarning after close() + GC
  • test_close_no_resource_warning_with_stderr_pipe — verifies stderr PIPE path is also covered

Closes #82

@KuaaMU KuaaMU requested a review from tt-a1i as a code owner April 30, 2026 06:40
AcpTransport.close() closed stdin and called terminate()/wait(),
but never closed the stdout (and stderr) pipes opened as
subprocess.PIPE. The file descriptor leaked until GC, triggering
ResourceWarning when running with -W error::ResourceWarning.

Fix: close stdout and stderr before terminate(), following the same
try/except pattern used for stdin. Catch both OSError and ValueError
to handle concurrent reader thread edge cases.

Closes mco-org#82
@KuaaMU KuaaMU force-pushed the fix/close-stdout-pipe-on-stop branch from c369e6e to f7d608d Compare April 30, 2026 09:35
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.

[Bug] ResourceWarning: unclosed stdout pipe in AcpTransport.stop()

2 participants