Kaydet (Commit) ba8474b7 authored tarafından Martin Panter's avatar Martin Panter

Issue #26309: Shut down SocketServer request if verify_request() is false

Based on patch by Aviv Palivoda.
üst 51b13e53
...@@ -296,6 +296,8 @@ class BaseServer: ...@@ -296,6 +296,8 @@ class BaseServer:
except: except:
self.handle_error(request, client_address) self.handle_error(request, client_address)
self.shutdown_request(request) self.shutdown_request(request)
else:
self.shutdown_request(request)
def handle_timeout(self): def handle_timeout(self):
"""Called if no new request arrives within self.timeout. """Called if no new request arrives within self.timeout.
......
...@@ -326,6 +326,29 @@ class SocketServerTest(unittest.TestCase): ...@@ -326,6 +326,29 @@ class SocketServerTest(unittest.TestCase):
SocketServer.TCPServer((HOST, -1), SocketServer.TCPServer((HOST, -1),
SocketServer.StreamRequestHandler) 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(): def test_main():
if imp.lock_held(): if imp.lock_held():
......
...@@ -50,6 +50,10 @@ Core and Builtins ...@@ -50,6 +50,10 @@ Core and Builtins
Library 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 #25939: On Windows open the cert store readonly in ssl.enum_certificates.
- Issue #24303: Fix random EEXIST upon multiprocessing semaphores creation with - Issue #24303: Fix random EEXIST upon multiprocessing semaphores creation with
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment