]> git.ipfire.org Git - thirdparty/Python/cpython.git/commit
gh-139116: tracemalloc: Detach thread state when acquiring tables_lock (GH-139449)
authorPetr Viktorin <encukou@gmail.com>
Tue, 30 Sep 2025 14:43:49 +0000 (16:43 +0200)
committerGitHub <noreply@github.com>
Tue, 30 Sep 2025 14:43:49 +0000 (16:43 +0200)
commit01157e0cdff1321a065b0a00c5a97460f52af07e
treeac7fb41d8f2bfb6a7d4d77112692770b9d429ad0
parentb2f5ad0c6d7cfd249c41bfbcdd0a75a9f21f1e72
gh-139116: tracemalloc: Detach thread state when acquiring tables_lock (GH-139449)

* gh-139116: tracemalloc: Detach thread state when acquiring tables_lock

This prevents a deadlock when:

- One thread is in `_PyTraceMalloc_Stop`, with `TABLES_LOCK` held, calling
  `PyRefTracer_SetTracer` which wants to stop the world
- Another is thread in `PyTraceMalloc_Track`, just attached thread state, waiting
  for `TABLES_LOCK`

Detaching the thread state while waiting for `TABLES_LOCK` allows
`PyRefTracer_SetTracer` to stop the world.

Co-authored-by: Peter Bierma <zintensitydev@gmail.com>
Misc/NEWS.d/next/Core_and_Builtins/2025-09-30-14-57-19.gh-issue-139116.nlVf40.rst [new file with mode: 0644]
Python/tracemalloc.c