Comment 5 for bug 1849971

Revision history for this message
Olaf Seibert (rhialto) wrote :

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
<socket.socket [closed] fd=-1, family=AddressFamily.AF_INET, type=SocketKind.SOCK_STREAM, proto=0>
(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))
print(s)
s.detach()
print(s)
s.shutdown(socket.SHUT_RDWR)
$ python3.7 sock.py
<socket.socket fd=3, family=AddressFamily.AF_INET, type=SocketKind.SOCK_STREAM, proto=6, laddr=('127.0.0.1', 62722), raddr=('127.0.0.1', 22)>
<socket.socket [closed] fd=-1, family=AddressFamily.AF_INET, type=SocketKind.SOCK_STREAM, proto=6>
Traceback (most recent call last):
  File "sock.py", line 7, in <module>
    s.shutdown(socket.SHUT_RDWR)
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.