summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_socketserver.py
diff options
context:
space:
mode:
authorJason R. Coombs <jaraco@jaraco.com>2020-12-31 20:19:30 (GMT)
committerGitHub <noreply@github.com>2020-12-31 20:19:30 (GMT)
commitb5711c940f70af89f2b4cf081a3fcd83924f3ae7 (patch)
tree18b74a6cbd3091b024db21c842a7162c8fad9578 /Lib/test/test_socketserver.py
parent3631d6deab064de0bb286ef2943885dca3c3075e (diff)
downloadcpython-b5711c940f70af89f2b4cf081a3fcd83924f3ae7.zip
cpython-b5711c940f70af89f2b4cf081a3fcd83924f3ae7.tar.gz
cpython-b5711c940f70af89f2b4cf081a3fcd83924f3ae7.tar.bz2
bpo-37193: Remove thread objects which finished process its request (GH-23127)
This reverts commit aca67da4fe68d5420401ac1782203d302875eb27.
Diffstat (limited to 'Lib/test/test_socketserver.py')
-rw-r--r--Lib/test/test_socketserver.py23
1 files changed, 23 insertions, 0 deletions
diff --git a/Lib/test/test_socketserver.py b/Lib/test/test_socketserver.py
index 7cdd115..954e033 100644
--- a/Lib/test/test_socketserver.py
+++ b/Lib/test/test_socketserver.py
@@ -277,6 +277,13 @@ class SocketServerTest(unittest.TestCase):
t.join()
s.server_close()
+ def test_close_immediately(self):
+ class MyServer(socketserver.ThreadingMixIn, socketserver.TCPServer):
+ pass
+
+ server = MyServer((HOST, 0), lambda: None)
+ server.server_close()
+
def test_tcpserver_bind_leak(self):
# Issue #22435: the server socket wouldn't be closed if bind()/listen()
# failed.
@@ -491,6 +498,22 @@ class MiscTestCase(unittest.TestCase):
self.assertEqual(server.shutdown_called, 1)
server.server_close()
+ def test_threads_reaped(self):
+ """
+ In #37193, users reported a memory leak
+ due to the saving of every request thread. Ensure that
+ not all threads are kept forever.
+ """
+ class MyServer(socketserver.ThreadingMixIn, socketserver.TCPServer):
+ pass
+
+ server = MyServer((HOST, 0), socketserver.StreamRequestHandler)
+ for n in range(10):
+ with socket.create_connection(server.server_address):
+ server.handle_request()
+ self.assertLess(len(server._threads), 10)
+ server.server_close()
+
if __name__ == "__main__":
unittest.main()