Commit 6aabcee
committed
Fix LibevConnection close() race causing EBADF errors (#614)
LibevConnection.close() closes the socket immediately while watchers
are stopped asynchronously in the next event loop iteration via
_loop_will_run(). This creates a race window where handle_read() or
handle_write() can operate on a closed socket fd, producing EBADF
errors that surface as ConnectionShutdown.
- Add is_closed/is_defunct guards in handle_read() and handle_write()
error paths to silently exit during shutdown instead of calling
defunct() with EBADF
- Set last_error in close() when connected_event is not yet set to
prevent factory() from returning a dead connection
- Set last_error on server-initiated close (EOF) in handle_read()
before calling close()1 parent f348637 commit 6aabcee
1 file changed
Lines changed: 12 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
300 | 300 | | |
301 | 301 | | |
302 | 302 | | |
303 | | - | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
304 | 307 | | |
305 | 308 | | |
306 | 309 | | |
| |||
332 | 335 | | |
333 | 336 | | |
334 | 337 | | |
| 338 | + | |
| 339 | + | |
335 | 340 | | |
336 | 341 | | |
337 | 342 | | |
| |||
365 | 370 | | |
366 | 371 | | |
367 | 372 | | |
| 373 | + | |
| 374 | + | |
368 | 375 | | |
369 | 376 | | |
370 | 377 | | |
371 | 378 | | |
372 | 379 | | |
373 | 380 | | |
| 381 | + | |
| 382 | + | |
374 | 383 | | |
375 | 384 | | |
376 | 385 | | |
377 | 386 | | |
378 | 387 | | |
379 | 388 | | |
380 | 389 | | |
| 390 | + | |
| 391 | + | |
381 | 392 | | |
382 | 393 | | |
383 | 394 | | |
| |||
0 commit comments