Skip to content

Commit c40f8b1

Browse files
committed
gh-135056: Add addCleanup calls to ensure test server thread exits.
1 parent 69e59e9 commit c40f8b1

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

Lib/test/test_httpservers.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -980,6 +980,11 @@ def test_extra_response_headers_concurrent_requests(self):
980980
server_thread = threading.Thread(
981981
target=threaded_server.serve_forever, args=(0.05,), daemon=True
982982
)
983+
# Clean up the server thread and server resources after the test,
984+
# with a timeout to prevent hanging, even if the finally block fails.
985+
self.addCleanup(server_thread.join, support.SHORT_TIMEOUT)
986+
self.addCleanup(threaded_server.server_close)
987+
self.addCleanup(threaded_server.shutdown)
983988
server_thread.start()
984989
results = []
985990
errors = []
@@ -1011,7 +1016,7 @@ def make_request():
10111016
finally:
10121017
threaded_server.shutdown()
10131018
threaded_server.server_close()
1014-
server_thread.join()
1019+
server_thread.join(timeout=support.SHORT_TIMEOUT)
10151020

10161021
# Only raise errors in the main thread, just the first one.
10171022
if errors:

0 commit comments

Comments
 (0)