Commit 2e949f8
committed
Fix stdio transport closing sys.stdin.buffer/sys.stdout.buffer on exit
When using transport='stdio', anyio.wrap_file() wraps a TextIOWrapper
around sys.stdin.buffer/sys.stdout.buffer. When the server exits and the
async file is closed, TextIOWrapper.close() propagates to close the
underlying buffer, making subsequent stdio operations fail with:
ValueError: underlying buffer has been closed
This adds a _DetachingTextIOWrapper that detaches from the buffer on
close, preventing the propagation. The original comment in the code
stated 'Purposely not using context managers for these, as we don't want
to close standard process handles' — this fix aligns the implementation
with that intent.
Fixes #19331 parent 616476f commit 2e949f8
1 file changed
Lines changed: 13 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
21 | 21 | | |
22 | 22 | | |
23 | 23 | | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
24 | 35 | | |
25 | 36 | | |
26 | 37 | | |
| |||
39 | 50 | | |
40 | 51 | | |
41 | 52 | | |
42 | | - | |
| 53 | + | |
43 | 54 | | |
44 | | - | |
| 55 | + | |
45 | 56 | | |
46 | 57 | | |
47 | 58 | | |
| |||
0 commit comments