Skip to content

Commit 10cb376

Browse files
beledouxdenisvstinner
authored andcommitted
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.
1 parent 25a525b commit 10cb376

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

Lib/socketserver.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,9 @@ def serve_forever(self, poll_interval=0.5):
230230

231231
while not self.__shutdown_request:
232232
ready = selector.select(poll_interval)
233+
# bpo-35017: shutdown() called during select(), exit immediately.
234+
if self.__shutdown_request:
235+
break
233236
if ready:
234237
self._handle_request_noblock()
235238

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
:meth:`socketserver.BaseServer.serve_forever` now exits immediately if it's
2+
:meth:`~socketserver.BaseServer.shutdown` method is called while it is
3+
polling for new events.

0 commit comments

Comments
 (0)