Skip to content

dict/func/code watchers may call dealloc callback with exception set #102385

Closed

Description

@carljm

The docs at https://python.readthedocs.io/en/stable/extending/newtypes.html#finalization-and-de-allocation note that dealloc funcs need to be careful to work correctly in the presence of a pending exception, because deallocation may happen in unwinding while an exception is pending.

func_dealloc, code_dealloc, and dict_dealloc all may call watcher callbacks with a deallocation event. We shouldn't call a user callback with a pending exception set; this could cause all kinds of hard-to-debug issues. We should save/restore the exception around the callback.

Activity

  1. added
    type-bugAn unexpected behavior, bug, or error
    on Mar 3, 2023
  2. self-assigned this
    on Mar 3, 2023
  3. carljm commented on Mar 4, 2023

    @carljm
    MemberAuthor

    On second thought, I think the performance cost of checking for a pending exception and then saving/restoring is too high, given that watchers are a low-level API intended for high performance. We should rather fix this by documenting that watchers may be called (in the case of dealloc events) with a pending exception set.

  4. carljm commented on Mar 8, 2023

    @carljm
    MemberAuthor

    Fixed in #102382

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions