[issue39700] asyncio.selector_events._SelectorTransport: Add logging when sock.getpeername() fails

David report at bugs.python.org
Mon Feb 24 10:51:51 EST 2020


David <dsternlicht at infinidat.com> added the comment:

Hi asvetlov,

Thank you for your reply.

I'm currently trying to debug a network issue, but I cannot determine the root cause of it because of lack of logs. It would be extremely helpful for my debugging if we could log the error that was raised by getpeername.

I noticed that in asyncio.proactor_events._set_socket_extra there *is* some logging of exceptions. 

```
def _set_socket_extra(transport, sock):
    transport._extra['socket'] = trsock.TransportSocket(sock)

    try:
        transport._extra['sockname'] = sock.getsockname()
    except socket.error:
        if transport._loop.get_debug():
            logger.warning(
                "getsockname() failed on %r", sock, exc_info=True)

    if 'peername' not in transport._extra:
        try:
            transport._extra['peername'] = sock.getpeername()
        except socket.error:
            # UDP sockets may not have a peer name
            transport._extra['peername'] = None
```

Although I see that there there's also a check `if transport._loop.get_debug()` so that it won't pollute the log. Would you like me to add that check to my patch too?

Thanks!

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue39700>
_______________________________________


More information about the Python-bugs-list mailing list