[New-bugs-announce] [issue28447] socket.getpeername() failure on broken TCP/IP connection
George,Y
report at bugs.python.org
Fri Oct 14 21:13:17 EDT 2016
New submission from George,Y:
I need to know the IP address on the other side of a broken TCP/IP connection.
"socket.getpeername()" fails to do the job sometimes because the connection has been closed, and Windows Error 10038 tells the connection is no longer a socket so that the method getpeername is wrongly used.
Here goes the code in main thread:
-----------
mailbox = queue.Queue()
read_sockets, write_sockets, error_sockets = select.select(active_socks,[],[],TIMEOUT)
for sock in read_sockets:
......
except:
mailbox.put( (("sock_err",sock), 'localhost') )
=========
The sub thread get this message from mailbox and try to analyze the broken socket, to simplify I put the code and output together:
-------------
print(sock)>>>
<socket.socket [closed] fd=-1, family=AFNET, type=SOCKSTREAM, proto=0>
sock.getpeername()>>>
OS.Error[WinError10038]an operation was attempted on something that is not a socket
=======
Surprisingly, this kind of error happen occasionally - sometimes the socket object is normal and getpeername() works fine.
So once a connection is broken, there is no way to tell the address to whom it connected?
----------
components: Library (Lib)
files: socket错误不识别.png
messages: 278679
nosy: George,Y
priority: normal
severity: normal
status: open
title: socket.getpeername() failure on broken TCP/IP connection
type: crash
versions: Python 3.4
Added file: http://bugs.python.org/file45095/socket错误不识别.png
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue28447>
_______________________________________
More information about the New-bugs-announce
mailing list