[issue37193] Memory leak while running TCP/UDPServer with socketserver.ThreadingMixIn
Martin Panter
report at bugs.python.org
Sun Jun 16 21:47:45 EDT 2019
Martin Panter <vadmium+py at gmail.com> added the comment:
Looking at the code, this would be caused by Issue 31233. I expect 3.7+ is affected. 3.6 has similar code, but the leaking looks to be disabled by default. 2.7 doesn't collect a "_threads" list at all.
Looks like Victor was aware of the leak when he changed the code: <https://bugs.python.org/issue31233#msg304619>, but maybe he pushed the code and then forgot about the problem.
A possible problem with Norihiro's solution is modifying the "_threads" list from multiple threads without any synchronization. (Not sure if that is a problem, or is it guaranteed to be okay due to GIL etc?) Also, since the thread is removing itself from the list, it will still run a short while after the removal, so there is a window when the "server_close" method will not wait for that thread. Might also defeat the "dangling thread" accounting that I believe was Victor's motivation for his change.
Wei's proposal is to check for cleaning up when a new request is handled. That relies on a new request coming in to free up memory. Perhaps we could use similar strategy to the Forking mixin, which I believe cleans up expired children periodically, without relying on a new request.
----------
keywords: +3.7regression
nosy: +martin.panter, vstinner
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue37193>
_______________________________________
More information about the Python-bugs-list
mailing list