Commit d8c7de2
committed
Drain stdout to EOF so _ProactorReadPipeTransport closes on Windows
One remaining leak on Windows CI: _ProactorReadPipeTransport (stdout)
was never closed, triggering ResourceWarning in a later test.
Root cause: anyio's StreamReaderWrapper.aclose() only calls
set_exception(ClosedResourceError()) on the Python-level StreamReader —
it never touches the underlying transport. On Windows,
_ProactorReadPipeTransport starts with _paused=True and only detects
pipe EOF when someone reads. The EOF-detection path is what calls
transport.close(): _eof_received() → self.close() → _sock = None.
Without a read, the transport lives until __del__.
Production stdio.py avoids this because its stdout_reader task
continuously reads stdout, so EOF is detected naturally. These tests
never read stdout, so the transport stays paused with an orphaned
overlapped read until GC.
Fix: drain stdout with a single receive() call in _terminate_and_reap.
The process is already dead, so the read immediately gets EOF
(EndOfStream on clean close, BrokenResourceError on abrupt RST,
ClosedResourceError on second call when already aclose()'d — all
caught by contextlib.suppress).
Note: the agent's suggested fix (stack.enter_async_context(proc) for
Process.__aexit__) wouldn't help — __aexit__ calls aclose() which has
the same stdout.aclose() issue. The drain is what actually closes the
transport.
Github-Issue: #17751 parent a070356 commit d8c7de2
1 file changed
+26
-19
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
6 | | - | |
| 6 | + | |
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
| |||
308 | 308 | | |
309 | 309 | | |
310 | 310 | | |
311 | | - | |
| 311 | + | |
312 | 312 | | |
313 | 313 | | |
314 | | - | |
315 | | - | |
316 | | - | |
317 | | - | |
318 | | - | |
319 | | - | |
320 | | - | |
321 | | - | |
322 | | - | |
323 | | - | |
324 | | - | |
325 | | - | |
326 | | - | |
327 | | - | |
328 | | - | |
329 | | - | |
330 | | - | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
331 | 336 | | |
332 | 337 | | |
333 | 338 | | |
| |||
336 | 341 | | |
337 | 342 | | |
338 | 343 | | |
| 344 | + | |
| 345 | + | |
339 | 346 | | |
340 | 347 | | |
341 | 348 | | |
| |||
0 commit comments