summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2018-10-26 14:10:41 (GMT)
committerGitHub <noreply@github.com>2018-10-26 14:10:41 (GMT)
commit8b1f52b5a93403acd7d112cd1c1bc716b31a418a (patch)
tree36281a10ac91a6800a39746bcbbf105bb6d40f83
parent38d7620baab96c702243cfa193377a38888ec10f (diff)
downloadcpython-8b1f52b5a93403acd7d112cd1c1bc716b31a418a.zip
cpython-8b1f52b5a93403acd7d112cd1c1bc716b31a418a.tar.gz
cpython-8b1f52b5a93403acd7d112cd1c1bc716b31a418a.tar.bz2
bpo-35017, socketserver: don't accept request after shutdown (GH-9952)
Prior to this revision, after the shutdown of a `BaseServer`, the server accepted a last single request if it was sent between the server socket polling and the polling timeout. This can be problematic for instance for a server restart for which you do not want to interrupt the service, by not closing the listening socket during the restart. One request failed because of this behavior. Note that only one request failed, following requests were not accepted, as expected. (cherry picked from commit 10cb3760e8631a27f5db1e51b05494e29306c671) Co-authored-by: Denis Ledoux <be.ledoux.denis@gmail.com>
-rw-r--r--Lib/socketserver.py3
-rw-r--r--Misc/NEWS.d/next/Library/2018-10-26-00-11-21.bpo-35017.6Ez4Cv.rst3
2 files changed, 6 insertions, 0 deletions
diff --git a/Lib/socketserver.py b/Lib/socketserver.py
index c4d544b..6a0aeee 100644
--- a/Lib/socketserver.py
+++ b/Lib/socketserver.py
@@ -234,6 +234,9 @@ class BaseServer:
while not self.__shutdown_request:
ready = selector.select(poll_interval)
+ # bpo-35017: shutdown() called during select(), exit immediately.
+ if self.__shutdown_request:
+ break
if ready:
self._handle_request_noblock()
diff --git a/Misc/NEWS.d/next/Library/2018-10-26-00-11-21.bpo-35017.6Ez4Cv.rst b/Misc/NEWS.d/next/Library/2018-10-26-00-11-21.bpo-35017.6Ez4Cv.rst
new file mode 100644
index 0000000..5682717
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2018-10-26-00-11-21.bpo-35017.6Ez4Cv.rst
@@ -0,0 +1,3 @@
+:meth:`socketserver.BaseServer.serve_forever` now exits immediately if it's
+:meth:`~socketserver.BaseServer.shutdown` method is called while it is
+polling for new events.