summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBert JW Regeer <xistence@0x58.com>2020-10-30 23:17:18 -0700
committerGitHub <noreply@github.com>2020-10-30 23:17:18 -0700
commit5faf6989f4ff019940f41e2ee4855615f41afcc5 (patch)
treedb90906172e96e99404b98c3795bf301d402a075
parent5570c7c9931d32f7558e08143d32125a745ec56b (diff)
parent25e093936d31dba3d5b042f842566729fb01668c (diff)
downloadwaitress-5faf6989f4ff019940f41e2ee4855615f41afcc5.tar.gz
Merge pull request #322 from Pylons/connection-overflow-warning
warn when the server stops listening for connections because it's in overflow
-rw-r--r--CHANGES.txt6
-rw-r--r--src/waitress/server.py24
-rw-r--r--tests/test_server.py14
3 files changed, 43 insertions, 1 deletions
diff --git a/CHANGES.txt b/CHANGES.txt
index f4d1acc..c62602e 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -3,6 +3,12 @@
- Drop Python 2.7 support
+- The server now issues warning output when it there are enough open
+ connections (controlled by "connection_limit"), that it is no longer
+ accepting new connections. This situation was previously difficult to
+ diagnose.
+ See https://github.com/Pylons/waitress/pull/322
+
1.4.4 (2020-06-01)
------------------
diff --git a/src/waitress/server.py b/src/waitress/server.py
index b053c69..b37980e 100644
--- a/src/waitress/server.py
+++ b/src/waitress/server.py
@@ -179,6 +179,7 @@ class BaseWSGIServer(wasyncore.dispatcher):
next_channel_cleanup = 0
socketmod = socket # test shim
asyncore = wasyncore # test shim
+ in_connection_overflow = False
def __init__(
self,
@@ -296,7 +297,28 @@ class BaseWSGIServer(wasyncore.dispatcher):
if now >= self.next_channel_cleanup:
self.next_channel_cleanup = now + self.adj.cleanup_interval
self.maintenance(now)
- return self.accepting and len(self._map) < self.adj.connection_limit
+
+ if self.accepting:
+ if (
+ not self.in_connection_overflow
+ and len(self._map) >= self.adj.connection_limit
+ ):
+ self.in_connection_overflow = True
+ self.logger.warning(
+ "total open connections reached the connection limit, "
+ "no longer accepting new connections"
+ )
+ elif (
+ self.in_connection_overflow
+ and len(self._map) < self.adj.connection_limit
+ ):
+ self.in_connection_overflow = False
+ self.logger.info(
+ "total open connections dropped below the connection limit, "
+ "listening again"
+ )
+ return not self.in_connection_overflow
+ return False
def writable(self):
return False
diff --git a/tests/test_server.py b/tests/test_server.py
index 05f6b4e..508b382 100644
--- a/tests/test_server.py
+++ b/tests/test_server.py
@@ -185,6 +185,7 @@ class TestWSGIServer(unittest.TestCase):
inst.adj = DummyAdj
inst._map = {"a": 1, "b": 2}
self.assertFalse(inst.readable())
+ self.assertTrue(inst.in_connection_overflow)
def test_readable_maplen_lt_connection_limit(self):
inst = self._makeOneWithMap()
@@ -192,6 +193,19 @@ class TestWSGIServer(unittest.TestCase):
inst.adj = DummyAdj
inst._map = {}
self.assertTrue(inst.readable())
+ self.assertFalse(inst.in_connection_overflow)
+
+ def test_readable_maplen_toggles_connection_overflow(self):
+ inst = self._makeOneWithMap()
+ inst.accepting = True
+ inst.adj = DummyAdj
+ inst._map = {"a": 1, "b": 2}
+ self.assertFalse(inst.in_connection_overflow)
+ self.assertFalse(inst.readable())
+ self.assertTrue(inst.in_connection_overflow)
+ inst._map = {}
+ self.assertTrue(inst.readable())
+ self.assertFalse(inst.in_connection_overflow)
def test_readable_maintenance_false(self):
import time