[Python-checkins] bpo-35017, socketserver: don't accept request after shutdown (GH-9952) (GH-10129)

Victor Stinner webhook-mailer at python.org
Fri Oct 26 11:15:25 EDT 2018


https://github.com/python/cpython/commit/6f97a50c86737458c6bed9970c8dc31a465eff22
commit: 6f97a50c86737458c6bed9970c8dc31a465eff22
branch: 2.7
author: Denis Ledoux <be.ledoux.denis at gmail.com>
committer: Victor Stinner <vstinner at redhat.com>
date: 2018-10-26T17:15:22+02:00
summary:

bpo-35017, socketserver: don't accept request after shutdown (GH-9952) (GH-10129)

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)

files:
A Misc/NEWS.d/next/Library/2018-10-26-00-11-21.bpo-35017.6Ez4Cv.rst
M Lib/SocketServer.py

diff --git a/Lib/SocketServer.py b/Lib/SocketServer.py
index 122430e362df..df56830f0550 100644
--- a/Lib/SocketServer.py
+++ b/Lib/SocketServer.py
@@ -229,6 +229,9 @@ def serve_forever(self, poll_interval=0.5):
                 # shutdown request and wastes cpu at all other times.
                 r, w, e = _eintr_retry(select.select, [self], [], [],
                                        poll_interval)
+                # bpo-35017: shutdown() called during select(), exit immediately.
+                if self.__shutdown_request:
+                    break
                 if self in r:
                     self._handle_request_noblock()
         finally:
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 000000000000..5682717adf70
--- /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.



More information about the Python-checkins mailing list