summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBert JW Regeer <bertjw@regeer.org>2023-01-22 20:59:41 -0700
committerBert JW Regeer <bertjw@regeer.org>2023-01-22 20:59:41 -0700
commit5903d585617683da4a1e8005b7f2d7f9b385e26b (patch)
treefed4ad7d6c9035c834020900a2043cdb9f3fb013
parent56e44fec0931ea6726a28fab96607f829854a219 (diff)
downloadwaitress-5903d585617683da4a1e8005b7f2d7f9b385e26b.tar.gz
Setting socket options may fail if remote has already disappeared
By the time we come around to accepting a connection on macOS, the remote may have already disappeared, in which case setting options on the socket may fail with an error. Instead of failing and shutting down the server we want to continue, so move the setting of socket options into the try/except block and log the error instead.
-rw-r--r--src/waitress/server.py6
1 files changed, 5 insertions, 1 deletions
diff --git a/src/waitress/server.py b/src/waitress/server.py
index 0378d48..bbb6819 100644
--- a/src/waitress/server.py
+++ b/src/waitress/server.py
@@ -305,15 +305,19 @@ class BaseWSGIServer(wasyncore.dispatcher):
if v is None:
return
conn, addr = v
+ self.set_socket_options(conn)
except OSError:
# Linux: On rare occasions we get a bogus socket back from
# accept. socketmodule.c:makesockaddr complains that the
# address family is unknown. We don't want the whole server
# to shut down because of this.
+ # macOS: On occasions when the remote has already closed the socket
+ # before we got around to accepting it, when we try to set the
+ # socket options it will fail. So instead just we log the error and
+ # continue
if self.adj.log_socket_errors:
self.logger.warning("server accept() threw an exception", exc_info=True)
return
- self.set_socket_options(conn)
addr = self.fix_addr(addr)
self.channel_class(self, conn, addr, self.adj, map=self._map)