diff options
author | Bert JW Regeer <bertjw@regeer.org> | 2017-01-17 00:05:10 -0700 |
---|---|---|
committer | Bert JW Regeer <bertjw@regeer.org> | 2017-01-17 00:13:16 -0700 |
commit | c9309bed67690a5c2a11b8043dab730ef807f18c (patch) | |
tree | f377e3271535f7d557120e5b91c0d0e1d904d657 | |
parent | 9ecb4b96d2ca56f12276859734c747246255050a (diff) | |
download | waitress-c9309bed67690a5c2a11b8043dab730ef807f18c.tar.gz |
Add fallback to numeric only nameinfo
-rw-r--r-- | waitress/server.py | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/waitress/server.py b/waitress/server.py index d3fbd79..79aa9b7 100644 --- a/waitress/server.py +++ b/waitress/server.py @@ -294,9 +294,21 @@ class TcpWSGIServer(BaseWSGIServer): self.bind(sockaddr) def getsockname(self): - return self.socketmod.getnameinfo( - self.socket.getsockname(), - self.socketmod.NI_NUMERICSERV) + try: + return self.socketmod.getnameinfo( + self.socket.getsockname(), + self.socketmod.NI_NUMERICSERV + ) + except: # pragma: no cover + # This only happens on Linux because a DNS issue is considered a + # temporary failure that will raise (even when NI_NAMEREQD is not + # set). Instead we try again, but this time we just ask for the + # numerichost and the numericserv (port) and return those. It is + # better than nothing. + return self.socketmod.getnameinfo( + self.socket.getsockname(), + self.socketmod.NI_NUMERICHOST | self.socketmod.NI_NUMERICSERV + ) def set_socket_options(self, conn): for (level, optname, value) in self.adj.socket_options: |