Commit 9938ae9
BashNetCorp
fix(stdio): handle BrokenResourceError in stdout_reader race
`stdio_client` has a race: `read_stream_writer.aclose()` in the context's
`finally` block can close the receiver while the background `stdout_reader`
task is mid-`send`. anyio then raises `BrokenResourceError`, which the outer
`except` does not cover (`ClosedResourceError` is the sibling class, raised
on already-closed streams, not streams closed during an in-flight send).
The exception propagates through the task group as `ExceptionGroup` and
fails every caller that exits the context while the subprocess is still
writing to stdout.
Wrap both `read_stream_writer.send(...)` sites in `try`/`except
(ClosedResourceError, BrokenResourceError): return` so `stdout_reader`
shuts down cleanly, and widen the outer `except` to the same union for
defense in depth. No API changes.
Adds `test_stdio_client_exits_cleanly_while_server_still_writing`:
spawns a subprocess that emits a burst of JSONRPC notifications, exits the
`stdio_client` context immediately, and asserts no exception propagates.
Fails before the fix (ExceptionGroup / BrokenResourceError), passes after.
Github-Issue:#19601 parent 3d7b311 commit 9938ae9
2 files changed
Lines changed: 54 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
153 | 153 | | |
154 | 154 | | |
155 | 155 | | |
156 | | - | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
157 | 160 | | |
158 | 161 | | |
159 | 162 | | |
160 | | - | |
161 | | - | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
162 | 174 | | |
163 | 175 | | |
164 | 176 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
37 | 37 | | |
38 | 38 | | |
39 | 39 | | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
40 | 79 | | |
41 | 80 | | |
42 | 81 | | |
| |||
0 commit comments