← 输入框|github.com|刷新
Skip to content

socketserver.ThreadingMixIn leaks running threads after server_close() #75416

Closed

Description

@vstinner
BPO 31233
Nosy @pitrou, @vstinner, @ned-deily, @vadmium
PRs
  • bpo-31233: socketserver.ThreadingMixIn.server_close() #3523
  • bpo-30830: logging.config.listen() calls server_close() #3524
  • bpo-31233, bpo-31151: Document socketserver changes #5417
  • 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:

    assignee = None
    closed_at = <Date 2018-05-29.22:00:51.118>
    created_at = <Date 2017-08-18.16:24:59.372>
    labels = ['3.7', 'library', 'performance']
    title = 'socketserver.ThreadingMixIn leaks running threads after server_close()'
    updated_at = <Date 2019-06-17.01:28:15.814>
    user = 'https://github.com/vstinner'

    bugs.python.org fields:

    activity = <Date 2019-06-17.01:28:15.814>
    actor = 'martin.panter'
    assignee = 'none'
    closed = True
    closed_date = <Date 2018-05-29.22:00:51.118>
    closer = 'vstinner'
    components = ['Library (Lib)']
    creation = <Date 2017-08-18.16:24:59.372>
    creator = 'vstinner'
    dependencies = []
    files = []
    hgrepos = ['376']
    issue_num = 31233
    keywords = ['patch']
    message_count = 19.0
    messages = ['300514', '300518', '300533', '300536', '302009', '302010', '302014', '302024', '302034', '302037', '304619', '307048', '311016', '311021', '311025', '311092', '316835', '318115', '345795']
    nosy_count = 4.0
    nosy_names = ['pitrou', 'vstinner', 'ned.deily', 'martin.panter']
    pr_nums = ['3523', '3524', '5417']
    priority = None
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'resource usage'
    url = 'https://bugs.python.org/issue31233'
    versions = ['Python 3.7']

    Activity

    1. vstinner commented on Aug 18, 2017

      @vstinner
      MemberAuthor

      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.

    2. added
      performancePerformance or resource usage
      stdlibStandard Library Python modules in the Lib/ directory
      on Aug 18, 2017
    3. pitrou commented on Aug 18, 2017

      @pitrou
      Member

      The difference is that letting a thread run doesn't create a zombie thread, so I don't think the issue is really similar.

    4. vstinner commented on Aug 18, 2017

      @vstinner
      MemberAuthor

      Oh, test_socketserver just failed with ENV_CHANGED on AMD64 Windows7 SP1 3.x:

      http://buildbot.python.org/all/builders/AMD64%20Windows7%20SP1%203.x/builds/865/steps/test/logs/stdio

      test_TCPServer (test.test_socketserver.SocketServerTest) ... creating server
      (...)
      waiting for server
      done

      Warning -- threading_cleanup() failed to cleanup -1 threads after 5 sec (count: 0, dangling: 1)

    5. vstinner commented on Aug 18, 2017

      @vstinner
      MemberAuthor

      New changeset 6966960 by Victor Stinner in branch 'master':
      bpo-30830: test_logging uses threading_setup/cleanup (bpo-3137)
      6966960

    6. vstinner commented on Sep 13, 2017

      @vstinner
      MemberAuthor

      Another recent example while testing bpo-31234:

      test_ThreadingUDPServer (test.test_socketserver.SocketServerTest) ...
      (...)
      done
      Warning -- threading_cleanup() detected 1 leaked threads (count: 1, dangling: 2)
      ok

    7. vstinner commented on Sep 13, 2017

      @vstinner
      MemberAuthor

      Multiple test_logging tests have been skipped until this issue is fixed: see bpo-30830 and commit 6966960.

    8. vstinner commented on Sep 13, 2017

      @vstinner
      MemberAuthor

      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":
      https://mail.python.org/pipermail/python-dev/2017-August/148826.html

      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.

    9. vstinner commented on Sep 13, 2017

      @vstinner
      MemberAuthor

      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?

    10. vstinner commented on Sep 13, 2017

      @vstinner
      MemberAuthor

      New changeset 97d7e65 by Victor Stinner in branch 'master':
      bpo-30830: logging.config.listen() calls server_close() (bpo-3524)
      97d7e65

    11. vstinner commented on Sep 13, 2017

      @vstinner
      MemberAuthor

      New changeset b8f4163 by Victor Stinner in branch 'master':
      bpo-31233: socketserver.ThreadingMixIn.server_close() (bpo-3523)
      b8f4163

    12. 4 remaining items

    13. added
      performancePerformance or resource usage
      and removed
      buildThe build process and cross-build
      on Nov 25, 2017
    14. vstinner commented on Nov 27, 2017

      @vstinner
      MemberAuthor

      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...

    15. ned-deily commented on Jan 28, 2018

      @ned-deily
      Member

      What's the status of this? Feature freeze is here.

    16. vstinner commented on Jan 28, 2018

      @vstinner
      MemberAuthor

      What's the status of this?

      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.

      Feature freeze is here.

      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.

    17. ned-deily commented on Jan 28, 2018

      @ned-deily
      Member

      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?

    18. vstinner commented on Jan 29, 2018

      @vstinner
      MemberAuthor

      New changeset db8189b by Victor Stinner in branch 'master':
      bpo-31233, bpo-31151: Document socketserver changes (bpo-5417)
      db8189b

    19. vstinner commented on May 16, 2018

      @vstinner
      MemberAuthor

      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.

    20. vstinner commented on May 29, 2018

      @vstinner
      MemberAuthor

      The bug has been fixed in Python 3.7.

    21. vadmium commented on Jun 17, 2019

      @vadmium
      Member

      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

    22. transferred this issue fromon Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Metadata

    Metadata

    Assignees

    No one assigned

      Labels

      3.7 (EOL)end of lifeperformancePerformance or resource usagestdlibStandard Library Python modules in the Lib/ directory

      Projects

      No projects

        Milestone

        No milestone

        Relationships

        None yet

        Development

        No branches or pull requests

        Issue actions