Commit 73c70ca
Nova
fix: prevent stdio transport from closing real process stdin/stdout
The stdio server transport wraps sys.stdin.buffer and sys.stdout.buffer
with TextIOWrapper for UTF-8 encoding. TextIOWrapper calls close() in
__del__, which closes the underlying buffer. When the server exits and
the AsyncFile wrappers are garbage collected, this closes the real
process stdio file descriptors (fd 0 and fd 1).
This causes ValueError on subsequent print() or input() calls in the
parent process after the MCP server exits (e.g., Ctrl+D exit).
Fix: use _NoCloseTextIOWrapper that overrides close() and __del__() to
prevent closing the underlying buffer. The standard process handles
should outlive the server.
Fixes #19331 parent b478bff commit 73c70ca
1 file changed
Lines changed: 21 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
29 | 29 | | |
30 | 30 | | |
31 | 31 | | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
32 | 51 | | |
33 | 52 | | |
34 | 53 | | |
| |||
39 | 58 | | |
40 | 59 | | |
41 | 60 | | |
42 | | - | |
| 61 | + | |
43 | 62 | | |
44 | | - | |
| 63 | + | |
45 | 64 | | |
46 | 65 | | |
47 | 66 | | |
| |||
0 commit comments