Skip to content

Commit

Permalink
More resiliant socket_info.getpeername() calling (#495)
Browse files Browse the repository at this point in the history
  • Loading branch information
tomchristie authored Nov 22, 2019
1 parent b845690 commit 4da64be
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions uvicorn/protocols/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,16 @@
def get_remote_addr(transport):
socket_info = transport.get_extra_info("socket")
if socket_info is not None:
info = socket_info.getpeername()
family = socket_info.family
try:
info = socket_info.getpeername()
except OSError:
# This case appears to inconsistently occur with uvloop
# bound to a unix domain socket.
family = None
info = None
else:
family = socket_info.family

if family in (socket.AF_INET, socket.AF_INET6):
return (str(info[0]), int(info[1]))
return None
Expand Down

0 comments on commit 4da64be

Please sign in to comment.