Commit cacd81b
PR-Contributor
fix(server): prevent stdio transport from closing original stdio handles
When using transport='stdio', the stdio_server context manager wraps
sys.stdin.buffer and sys.stdout.buffer in TextIOWrapper. When these
wrappers are closed (either explicitly or when exiting the context),
they also close the underlying buffers, causing subsequent stdio
operations to fail with ValueError.
This fix duplicates the file descriptors before wrapping them, so that
the original stdin/stdout remain open after the transport is closed.
Fixes #19331 parent d5b9155 commit cacd81b
1 file changed
+9
-2
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
| 20 | + | |
20 | 21 | | |
21 | 22 | | |
22 | 23 | | |
| |||
38 | 39 | | |
39 | 40 | | |
40 | 41 | | |
| 42 | + | |
| 43 | + | |
41 | 44 | | |
42 | | - | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
43 | 48 | | |
44 | | - | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
45 | 52 | | |
46 | 53 | | |
47 | 54 | | |
| |||
0 commit comments