29 ms·
Why would they call shutdown and then immediately close? Just call close immediately. In fact, there is almost no need for anyone ever to call shutdown. It m
by fefe23 5y ago
Why would they call shutdown and then immediately close?
Just call close immediately.
In fact, there is almost no need for anyone ever to call shutdown.
It may make sense if you want to pass a socket descriptor to another process and you only want them to read from the socket, not write to it, to call a unidirectional shutdown on it before passing it on. But shutdown RDWR and then close is just silly.
The proper fix is not to add more exception handling but to remove the shutdown line altogether.
- postpawl 5y agoThis SO post describes how shutdown is different than close: https://stackoverflow.com/questions/409783/socket-shutdown-vs-socket-close#598759 https://stackoverflow.com/questions/409783/socket-shutdown-v... So maybe shutdown helps in case other processes are doing something with the socket? I saw this same shutdown + close pattern in cpython code, but urllib3 doesn’t call shutdown before closing the socket (they have a TODO about it). I’m also curious if calling shutdown is necessary.