Skip to content
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

Fix and improve errors handling in the garbage collector #77803

Closed
serhiy-storchaka opened this issue May 23, 2018 · 8 comments
Closed

Fix and improve errors handling in the garbage collector #77803

serhiy-storchaka opened this issue May 23, 2018 · 8 comments
Labels
3.7 (EOL) end of life 3.8 only security fixes interpreter-core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error

Comments

@serhiy-storchaka
Copy link
Member

BPO 33622
Nosy @pitrou, @vstinner, @serhiy-storchaka, @miss-islington
PRs
  • bpo-33622: Fix issues with handling errors in the GC. #7078
  • [3.7] bpo-33622: Fix issues with handling errors in the GC. (GH-7078) #7094
  • [3.6] bpo-33622: Fix issues with handling errors in the GC. (GH-7078) #7095
  • [2.7] bpo-33622: Fix issues with handling errors in the GC. (GH-7078) #7096
  • bpo-33622: Add checks for exceptions leaks in the garbage collector. #7126
  • 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 2019-03-21.13:09:05.227>
    created_at = <Date 2018-05-23.17:41:20.401>
    labels = ['interpreter-core', '3.8', 'type-bug', '3.7']
    title = 'Fix and improve errors handling in the garbage collector'
    updated_at = <Date 2019-03-21.13:09:05.227>
    user = 'https://github.com/serhiy-storchaka'

    bugs.python.org fields:

    activity = <Date 2019-03-21.13:09:05.227>
    actor = 'serhiy.storchaka'
    assignee = 'none'
    closed = True
    closed_date = <Date 2019-03-21.13:09:05.227>
    closer = 'serhiy.storchaka'
    components = ['Interpreter Core']
    creation = <Date 2018-05-23.17:41:20.401>
    creator = 'serhiy.storchaka'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 33622
    keywords = ['patch']
    message_count = 8.0
    messages = ['317431', '317567', '317568', '317569', '317617', '317732', '318048', '318290']
    nosy_count = 4.0
    nosy_names = ['pitrou', 'vstinner', 'serhiy.storchaka', 'miss-islington']
    pr_nums = ['7078', '7094', '7095', '7096', '7126']
    priority = 'low'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue33622'
    versions = ['Python 2.7', 'Python 3.6', 'Python 3.7', 'Python 3.8']

    @serhiy-storchaka
    Copy link
    Member Author

    There are following bugs in the garbage collector.

    • If the garbage collector fails to add an object with __del__ or referenced by an object with __del__ to gc.garbage (in handle_legacy_finalizers()), it leaks it and other not added objects with __del__ and referenced by them. They become no longer accessible by the garbage collector.

    • PyGC_Collect() is not documented, but it is a public C API. And it can be called by user with an exception set. PyGC_Collect() then can either crash or just silent the exception. It is safer to safe possible exception and restore it after collecting.

    • A pointer to released member can be used (compared with NULL) in invoke_gc_callback(). This is an undefined behavior.

    @serhiy-storchaka serhiy-storchaka added 3.7 (EOL) end of life 3.8 only security fixes interpreter-core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error labels May 23, 2018
    @serhiy-storchaka serhiy-storchaka changed the title Fix and improve errors handling in the garbage collector Fix errors handling in the garbage collector May 23, 2018
    @serhiy-storchaka
    Copy link
    Member Author

    New changeset 301e3cc by Serhiy Storchaka in branch 'master':
    bpo-33622: Fix issues with handling errors in the GC. (GH-7078)
    301e3cc

    @miss-islington
    Copy link
    Contributor

    New changeset 2fe940c by Miss Islington (bot) in branch '3.7':
    bpo-33622: Fix issues with handling errors in the GC. (GH-7078)
    2fe940c

    @serhiy-storchaka
    Copy link
    Member Author

    New changeset f0e04b2 by Serhiy Storchaka in branch '3.6':
    [3.6] bpo-33622: Fix issues with handling errors in the GC. (GH-7078) (GH-7095)
    f0e04b2

    @serhiy-storchaka
    Copy link
    Member Author

    New changeset 9044cd6 by Serhiy Storchaka in branch '2.7':
    [2.7] bpo-33622: Fix issues with handling errors in the GC. (GH-7078) (bpo-7096)
    9044cd6

    @serhiy-storchaka serhiy-storchaka changed the title Fix errors handling in the garbage collector Fix and improve errors handling in the garbage collector May 26, 2018
    @serhiy-storchaka
    Copy link
    Member Author

    PR 7126 adds several assert(!PyErr_Occurred()) for earlier detection of leaked exceptions. And the failure in adding to gc.garbage is no longer fatal. It is better to not add an object to gc.garbage in this iteration than crash when we run garbage collection when have no memory.

    @serhiy-storchaka
    Copy link
    Member Author

    New changeset c4653c9 by Serhiy Storchaka in branch 'master':
    bpo-33622: Add checks for exceptions leaks in the garbage collector. (GH-7126)
    c4653c9

    @serhiy-storchaka
    Copy link
    Member Author

    See bpo-33712, bpo-33713 and bpo-33714 for three cases in the stdlib where an exception can be set in the tp_clear handler. This caused a crash in the garbage collector, or can be just silenced if failed at the shutdown stage. In the master branch it will cause writing a traceback to the stderr. It would be better to handle exceptions locally in the tp_clear handlers. But perhaps it may be worth to handle leaked exceptions in the garbage collector too. I'm just not sure about a solution. Writing a traceback to the stderr can cause a regression if it was just silenced before. But silencing it can hide bugs.

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    3.7 (EOL) end of life 3.8 only security fixes interpreter-core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    2 participants