Skip to content

atexit.unregister() can remove wrong callback #142881

Description

@serhiy-storchaka

Bug report

atexit.unregister() can call the user __eq__() when it searches the callback(s) to remove. If __eq__() returns true, the callback is removed by index. But __eq__() can call arbitrary code, it can release the GIL, and atexit.unregister() can be called in other thread. If it removes the callback at the current index or before current index, the current index will no point to the compared callable, and the following deletion will delete wrong callable.

This issue is similar to #112127, but causes different symptoms.

Linked PRs

Activity

  1. added
    type-bugAn unexpected behavior, bug, or error
    3.13only security fixes
    3.14bugs and security fixes
    3.15bugs and security fixes
    on Dec 17, 2025
  2. johnslavik commented on Dec 17, 2025

    @johnslavik
    Member

    @ZeroIntensity extension-modules

  3. added a commit that references this issue on Dec 17, 2025
  4. added a commit that references this issue on Jan 12, 2026
  5. added a commit that references this issue on Jan 12, 2026
  6. added a commit that references this issue on Jan 12, 2026
  7. serhiy-storchaka commented on Jan 12, 2026

    @serhiy-storchaka
    MemberAuthor

    3.13 required completely different solution than 3.14+.

  8. added a commit that references this issue on Jan 12, 2026
  9. added a commit that references this issue on Jan 12, 2026
  10. added a commit that references this issue on Jan 12, 2026
  11. added a commit that references this issue on Feb 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

3.13only security fixes3.14bugs and security fixes3.15bugs and security fixesextension-modulesC modules in the Modules dirtype-bugAn unexpected behavior, bug, or error

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions