classification
Title: pydoc: ServerThread.stop() leaves a dangling thread
Type: resource usage Stage: resolved
Components: Library (Lib) Versions: Python 3.7
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: haypo, pitrou
Priority: normal Keywords:

Created on 2017-08-18 23:50 by haypo, last changed 2017-08-22 14:57 by haypo. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 3151 merged haypo, 2017-08-18 23:51
PR 3177 closed haypo, 2017-08-22 09:57
Messages (4)
msg300556 - (view) Author: STINNER Victor (haypo) * (Python committer) Date: 2017-08-18 23:50
When using https://github.com/python/cpython/pull/3138 I see that test_pydoc leaves a dangling thread. The bug comes from test_server() which uses pydoc ServerThread.

ServerThread.stop() and test_pydoc don't join the thread. Moreover, ServerThread.docserver has a reference cycle through the DocServer.callback attribute.

Attached PR modifies ServerThread.stop() to join itself (the thread), to wait until the HTTP server completes, and then explicitly break the reference cycle.

With the PR, pydoc may hang if a bad HTTP client. So another option is to only modify test_pydoc to join() + break the ref cycle.
msg300557 - (view) Author: STINNER Victor (haypo) * (Python committer) Date: 2017-08-18 23:52
This issue is similar to bpo-31151: socketserver ForkingMixIn.server_close() leaks zombie processes.
msg300652 - (view) Author: STINNER Victor (haypo) * (Python committer) Date: 2017-08-21 21:24
New changeset 4cab2cd0c05fcda5fcb128c9eb230253fff88c21 by Victor Stinner in branch 'master':
bpo-31238: pydoc ServerThread.stop() now joins itself (#3151)
https://github.com/python/cpython/commit/4cab2cd0c05fcda5fcb128c9eb230253fff88c21
msg300701 - (view) Author: STINNER Victor (haypo) * (Python committer) Date: 2017-08-22 14:57
I left Python 2.7 and 3.6 unchanged to focus on fixing dangling threads and other similar bugs in the master branch first. I will see later if we really need to backport the fix to stable branches. In the meanwhile, I close the issue.
History
Date User Action Args
2017-08-22 14:57:00hayposetmessages: + msg300701
2017-08-22 14:55:52hayposetstatus: open -> closed
resolution: fixed
stage: resolved
2017-08-22 09:57:15hayposetpull_requests: + pull_request3215
2017-08-21 21:24:42hayposetmessages: + msg300652
2017-08-21 17:37:33serhiy.storchakasetnosy: + pitrou
2017-08-18 23:52:39hayposetmessages: + msg300557
2017-08-18 23:51:09hayposetpull_requests: + pull_request3185
2017-08-18 23:50:45haypocreate