-
-
Notifications
You must be signed in to change notification settings - Fork 30.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
socketserver.ThreadingMixIn leaks running threads after server_close() #75416
Comments
test_logging has a race condition: sometimes, it leaks dangling threads on FreeBSD: bpo-30830. I identified the root issue: socketserver.ThreadingMixIn spawns threads without waiting for their completion in server_close(). This issue is very similar to socketserver.ForkingMixIn which leaks child processes and so create zombie processes. See bpo-31151. |
The difference is that letting a thread run doesn't create a zombie thread, so I don't think the issue is really similar. |
Oh, test_socketserver just failed with ENV_CHANGED on AMD64 Windows7 SP1 3.x: test_TCPServer (test.test_socketserver.SocketServerTest) ... creating server Warning -- threading_cleanup() failed to cleanup -1 threads after 5 sec (count: 0, dangling: 1) |
Another recent example while testing bpo-31234: test_ThreadingUDPServer (test.test_socketserver.SocketServerTest) ... |
Attached PR 3523 is a temporary solution until we agree how to handle these threads and child processes in socketserver. I wrote the PR to fix "dangling threads" warnings to fix random buildbot failures. The PR fixes warnings but also reenable test_logging tests which are currently skipped. These tests were skipped by bpo-30830 to prevent random buildbot failures. See also the thread on the python-dev mailing list to discuss about bpo-31151 "socketserver.ForkingMixIn.server_close() leaks zombie processes": I tag this issue as release blocker as a remainder that we have to agree how to handle threads/processes before Python 3.7 feature freeze. |
Again, PR 3523 is a temporary fix to unblock the situation. For a proper fix, I have a question: Should server_close() calls self.close_request(request) on thread requests? |
The current code leaks memory since it never clears threads which completed. We need a cleanup function similar to ForkingMixIn.collect_children() which is called by handle_timeout() and service_actions(). We can check if a thread is alive: thread.is_alive(), to decide to remove it or not. Moreover, maybe we should keep a list of weak references? |
Klon666 added 96a6cbc repository. But this URL is unrelated. It looks like a bot spamming the bug tracker and I don't see how to remove the URL... |
What's the status of this? Feature freeze is here. |
The status is bad. The commit b8f4163 is backward incompatible, it's not documented in the "Porting the Python 3.7" section of What's New in Python 3.7, and it's not possible to opt-in for the previous behaviour.
IMHO it's ok to post-pone this issue to beta2. IMHO it's better to wait until all threads complete on server_close(), and it's possible to workaround the issue using daemon_threads = True which can be seen as the option to opt-in for the previous behaviour. |
If we're going to leave this open until 3.7.0b2, can you at least add a brief warning in the "Porting section" for b1 that the issue is unresolved? |
I created bpo-33540: "socketserver: Add an opt-in option to get Python 3.6 behaviour on server_close()". I set the release blocker priority on this new issue. |
The bug has been fixed in Python 3.7. |
FYI the change here to remember all the thread objects ever created looks to be the cause of the memory leak reported in bpo-37193 |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: