Oh, if you close() the socket before the shutdown, it results in "OSError: [Errno 9] Bad file descriptor", so that is not what is happening.
I'll be happy to just stub out the call do shutdown() if it takes too long to find a root cause here. But maybe I found something: I stuck a pdb.set_trace() just before the shutdown(), and it seems that the socket object is not quite as expected:
Oh, if you close() the socket before the shutdown, it results in "OSError: [Errno 9] Bad file descriptor", so that is not what is happening.
I'll be happy to just stub out the call do shutdown() if it takes too long to find a root cause here. But maybe I found something: I stuck a pdb.set_trace() just before the shutdown(), and it seems that the socket object is not quite as expected:
(Pdb) sock AddressFamily. AF_INET, type=SocketKind .SOCK_STREAM, proto=0>
<socket.socket [closed] fd=-1, family=
(Pdb) sock._io_refs
0
although an attempt to simulate this still doesn't get EINVAL:
$ cat sock.py
import socket
s = socket. create_ connection( ("127.0. 0.1", 22)) socket. SHUT_RDWR) AddressFamily. AF_INET, type=SocketKind .SOCK_STREAM, proto=6, laddr=('127.0.0.1', 62722), raddr=('127.0.0.1', 22)> AddressFamily. AF_INET, type=SocketKind .SOCK_STREAM, proto=6> socket. SHUT_RDWR)
print(s)
s.detach()
print(s)
s.shutdown(
$ python3.7 sock.py
<socket.socket fd=3, family=
<socket.socket [closed] fd=-1, family=
Traceback (most recent call last):
File "sock.py", line 7, in <module>
s.shutdown(
OSError: [Errno 9] Bad file descriptor
Another difference is proto=6 in the my test versus proto=0 in the real case.
Could the socket maybe a listening socket or something? (just wild guesswork)
-Olaf.