Commit 416f501
committed
fix(client): tolerate invalid UTF-8 from server stdout in stdio_client
Closes #2454.
stdio_client decoded child stdout with encoding_error_handler="strict",
so a server emitting malformed bytes mid-session raised UnicodeDecodeError
inside the decode loop, escaping both except clauses and tearing down the
transport task group (surfacing as an ExceptionGroup out of the context
manager) instead of surfacing the bad line as an in-stream parse error.
Default encoding_error_handler to "replace" so invalid bytes become U+FFFD;
the malformed line then fails JSON validation and is delivered as an Exception
via _parse_line, keeping the transport alive for subsequent valid messages.
This mirrors the server-side stdin hardening (errors="replace") referenced
in the issue (#2302).
Verified: repro that crashed the task group on main now surfaces a parse
error then reads the following valid message; new regression test fails
(5s task-group hang) without the fix, passes with it. ruff + pyright clean,
238 client/stdio tests pass.1 parent cf110e3 commit 416f501
2 files changed
Lines changed: 32 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
106 | 106 | | |
107 | 107 | | |
108 | 108 | | |
109 | | - | |
110 | | - | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
111 | 116 | | |
112 | 117 | | |
113 | 118 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
307 | 307 | | |
308 | 308 | | |
309 | 309 | | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
310 | 335 | | |
311 | 336 | | |
312 | 337 | | |
| |||
0 commit comments