Repository navigation
Commit 7c5985b
gh-162016: Back off when stdin is falsely reported writable
With stdin non-blocking, a pipe that poll() keeps reporting as writable
while it is full made communicate() spin: select() returned at once,
write() raised BlockingIOError, and the loop repeated, using a full core
until the child read its input or the timeout expired.
After a write that would block, take stdin out of the selector for a
delay that doubles from 1 ms to 50 ms and resets on the next successful
write. The other pipes are still serviced during the delay, and any
activity on them ends it early, since output from the child suggests it
has also consumed input.
Measured on macOS 27.2 with the system-wide pipe buffer limit reached,
for a child that never reads stdin and communicate(timeout=3): 3.00 s of
CPU before this change, 0.01 s after.
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>1 parent 8b99805 commit 7c5985b
1 file changed
Lines changed: 29 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
242 | 242 | | |
243 | 243 | | |
244 | 244 | | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
245 | 251 | | |
246 | 252 | | |
247 | 253 | | |
| |||
282 | 288 | | |
283 | 289 | | |
284 | 290 | | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
285 | 295 | | |
286 | | - | |
| 296 | + | |
287 | 297 | | |
288 | 298 | | |
289 | 299 | | |
290 | 300 | | |
291 | | - | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
292 | 306 | | |
293 | 307 | | |
294 | 308 | | |
295 | 309 | | |
296 | 310 | | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
297 | 317 | | |
298 | 318 | | |
299 | 319 | | |
300 | 320 | | |
301 | 321 | | |
302 | 322 | | |
303 | | - | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
304 | 329 | | |
305 | 330 | | |
306 | 331 | | |
307 | 332 | | |
308 | 333 | | |
309 | 334 | | |
310 | 335 | | |
| 336 | + | |
311 | 337 | | |
312 | 338 | | |
313 | 339 | | |
| |||
0 commit comments