Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🐛 Suppress legit OS errors on socket shutdown
When closing a socket we normally want to terminate the transport- level connection by sending a TCP FIN packet over the wire. This works great if the client is willing to perform a 3-way handshake but sometimes the client-side just drops the connection by sending an RST instead of a FIN. In this case, our server-side `socket.shutdown()` call will raise an OSError (socket.error on Python 2) or its derivatives. Which is perfectly fine and it's alright for us to ignore those. The kernel socket close helper rewrite introduced a behavior of only suppressing ENOTCONN in v8.4.8 (the case when the client is no longer with us) but it left own a few other cases that may be happening too. This change fixes that by extending the list of errors that are to be suppressed. Here's what's handled from now on: * ENOTCONN — client is no longer connected * EPIPE — write on a pipe while the other end has been closed * ESHUTDOWN — write on a socket which has been shutdown for writing * ECONNRESET — connection is reset by the peer Fixes #341 Refs: * https://en.wikipedia.org/wiki/Transmission_Control_Protocol#Connection_termination * #341 (comment)
- Loading branch information