Skip to content

dynload_shlib does not close ldl handles when the interpreter is shut down #67591

Open

Description

@Adam
mannequin
BPO 23402
Nosy @ericsnowcurrently
Files
  • python-dlopen.diff
  • 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 = None
    created_at = <Date 2015-02-06.18:21:40.551>
    labels = ['interpreter-core', 'type-bug']
    title = 'dynload_shlib does not close ldl handles when the interpreter is shut down'
    updated_at = <Date 2018-05-16.18:12:06.270>
    user = 'https://bugs.python.org/Adam'

    bugs.python.org fields:

    activity = <Date 2018-05-16.18:12:06.270>
    actor = 'eric.snow'
    assignee = 'none'
    closed = False
    closed_date = None
    closer = None
    components = ['Interpreter Core']
    creation = <Date 2015-02-06.18:21:40.551>
    creator = 'Adam'
    dependencies = []
    files = ['38028']
    hgrepos = []
    issue_num = 23402
    keywords = ['patch']
    message_count = 2.0
    messages = ['235490', '287380']
    nosy_count = 3.0
    nosy_names = ['eric.snow', 'Adam', 'Super Bo']
    pr_nums = []
    priority = 'normal'
    resolution = None
    stage = None
    status = 'open'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue23402'
    versions = ['Python 2.7']

    Activity

    1. Adam commented on Feb 6, 2015

      Adammannequin
      MannequinAuthor

      I think dynload_shlib (and maybe some of the other non-ldl dynamic library loaders?) should close the libraries when the interpreter is shut down. Currently the handles are not ever closed and in ldl's case sometimes leaked.

      The reason I desire this behavior is I have Python opening a shared library that I also open (all within the same process), and I want to be able to reload the library at runtime (via dlclose() + dlopen()) by shutting down the Python interpreter, dlclose()/dlopen(), and re-starting Python on the other side, however having the hanging reference to the library within the interpreter is preventing my dlclose() call from unloading the library.

      I have attached a patch for dynload_shlib.c that tracks all handles returned by dlopen() and will close them properly when the interpreter is shut down.

    2. added
      interpreter-core(Objects, Python, Grammar, and Parser dirs)
      type-bugAn unexpected behavior, bug, or error
      on Feb 6, 2015
    3. SuperBo commented on Feb 9, 2017

      SuperBomannequin
      Mannequin

      I think dynload_unload_all() should be called in PyImport_Cleanup() function.

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

      interpreter-core(Objects, Python, Grammar, and Parser dirs)type-bugAn unexpected behavior, bug, or error

      Projects

      No projects

        Milestone

        No milestone

        Relationships

        None yet

        Development

        No branches or pull requests

        Issue actions