[Python-checkins] cpython (merge 3.5 -> default): Issue #26309: Merge socketserver fix from 3.5

martin.panter python-checkins at python.org
Thu Feb 18 06:54:36 EST 2016


https://hg.python.org/cpython/rev/0768edf5878d
changeset:   100258:0768edf5878d
parent:      100256:6f0d3ae9f1f3
parent:      100257:651a6d47bc78
user:        Martin Panter <vadmium+py at gmail.com>
date:        Thu Feb 18 11:01:32 2016 +0000
summary:
  Issue #26309: Merge socketserver fix from 3.5

files:
  Lib/socketserver.py           |   2 +
  Lib/test/test_socketserver.py |  24 +++++++++++++++++++++++
  Misc/NEWS                     |   4 +++
  3 files changed, 30 insertions(+), 0 deletions(-)


diff --git a/Lib/socketserver.py b/Lib/socketserver.py
--- a/Lib/socketserver.py
+++ b/Lib/socketserver.py
@@ -319,6 +319,8 @@
             except:
                 self.handle_error(request, client_address)
                 self.shutdown_request(request)
+        else:
+            self.shutdown_request(request)
 
     def handle_timeout(self):
         """Called if no new request arrives within self.timeout.
diff --git a/Lib/test/test_socketserver.py b/Lib/test/test_socketserver.py
--- a/Lib/test/test_socketserver.py
+++ b/Lib/test/test_socketserver.py
@@ -280,6 +280,30 @@
                 socketserver.TCPServer((HOST, -1),
                                        socketserver.StreamRequestHandler)
 
+    def test_shutdown_request_called_if_verify_request_false(self):
+        # Issue #26309: BaseServer should call shutdown_request even if
+        # verify_request is False
+        shutdown_called = False
+
+        class MyServer(socketserver.TCPServer):
+            def verify_request(self, request, client_address):
+                return False
+
+            def shutdown_request(self, request):
+                nonlocal shutdown_called
+                shutdown_called = True
+                super().shutdown_request(request)
+
+        def connect_to_server(proto, addr):
+            s = socket.socket(proto, socket.SOCK_STREAM)
+            s.connect(addr)
+            s.close()
+
+        self.run_server(MyServer,
+                        socketserver.StreamRequestHandler,
+                        connect_to_server)
+        self.assertEqual(shutdown_called, True)
+
 
 class MiscTestCase(unittest.TestCase):
 
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -186,6 +186,10 @@
 Library
 -------
 
+- Issue #26309: In the "socketserver" module, shut down the request (closing
+  the connected socket) when verify_request() returns false.  Patch by Aviv
+  Palivoda.
+
 - Issue #25939: On Windows open the cert store readonly in ssl.enum_certificates.
 
 - Issue #25995: os.walk() no longer uses FDs proportional to the tree depth.

-- 
Repository URL: https://hg.python.org/cpython


More information about the Python-checkins mailing list