Skip to content

tracemalloc regression: deadlocks in 3.12.9 #130093

@itamarst

Description

@itamarst

Bug report

Bug description:

After recent changes, Polars debug builds, which integrate tracemalloc tracking, started experiencing deadlocks. Ripping out the tracemalloc integration fixed them (pola-rs/polars#21231). This started happening specifically when GitHub Actions switched to 3.12.9. I imagine this is due to the recent tracemalloc bug fixes.

No reproducer yet, but as a starting point:

  1. I am fairly certain this was not after doing tracemalloc.start(), since it happened in e.g. doctest runs that don't do that at all.
  2. Polars in this mode would trace Rust allocations using PyTraceMalloc_Track(): https://github.com/pola-rs/polars/blob/f378b24aeaaa14a8e7dacb6b35103424e8b97f1c/py-polars/src/memory.rs#L53
  3. Polars is heavily multi-threaded, and tracemalloc memory tracking would happen both while holding GIL and not holding GIL.

So this suggests some mixture of GIL-holding and non-GIL holding threads calling PyTraceMalloc_Track() and friends can cause deadlocks.

CPython versions tested on:

3.12

Operating systems tested on:

Linux

Metadata

Metadata

Assignees

No one assigned

    Labels

    type-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions