summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMartin Panter <vadmium+py@gmail.com>2016-02-18 10:43:55 (GMT)
committerMartin Panter <vadmium+py@gmail.com>2016-02-18 10:43:55 (GMT)
commitba8474b77dd86d8dde40eaa7a4a6715a476d6242 (patch)
tree7b87c2188df2894c8789c1b7a3a9a24ff295e079
parent51b13e53fcd0dfc0fbaa2be9cab7814e5f98233e (diff)
downloadcpython-ba8474b77dd86d8dde40eaa7a4a6715a476d6242.zip
cpython-ba8474b77dd86d8dde40eaa7a4a6715a476d6242.tar.gz
cpython-ba8474b77dd86d8dde40eaa7a4a6715a476d6242.tar.bz2
Issue #26309: Shut down SocketServer request if verify_request() is false
Based on patch by Aviv Palivoda.
-rw-r--r--Lib/SocketServer.py2
-rw-r--r--Lib/test/test_socketserver.py23
-rw-r--r--Misc/NEWS4
3 files changed, 29 insertions, 0 deletions
diff --git a/Lib/SocketServer.py b/Lib/SocketServer.py
index 33f7fb4..80130b7 100644
--- a/Lib/SocketServer.py
+++ b/Lib/SocketServer.py
@@ -296,6 +296,8 @@ class BaseServer:
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
index 714ca4a..73754c6 100644
--- a/Lib/test/test_socketserver.py
+++ b/Lib/test/test_socketserver.py
@@ -326,6 +326,29 @@ class SocketServerTest(unittest.TestCase):
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
+ result = {"shutdown_called": False}
+
+ class MyServer(SocketServer.TCPServer):
+ def verify_request(self, request, client_address):
+ return False
+
+ def shutdown_request(self, request):
+ result["shutdown_called"] = True
+ SocketServer.TCPServer.shutdown_request(self, 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(result["shutdown_called"], True)
+
def test_main():
if imp.lock_held():
diff --git a/Misc/NEWS b/Misc/NEWS
index 7635529..d83ac5b 100644
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -50,6 +50,10 @@ Core and Builtins
Library
-------
+- Issue #26309: In the "socketserver" module, shut down the request (closing
+ the connected socket) when verify_request() returns false. Based on patch
+ by Aviv Palivoda.
+
- Issue #25939: On Windows open the cert store readonly in ssl.enum_certificates.
- Issue #24303: Fix random EEXIST upon multiprocessing semaphores creation with