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

[3.12] gh-128679: Fix tracemalloc.stop() race conditions (#128897) #129022

Merged
merged 1 commit into from
Jan 19, 2025

Conversation

vstinner
Copy link
Member

@vstinner vstinner commented Jan 19, 2025

tracemalloc_alloc(), tracemalloc_realloc(), PyTraceMalloc_Track(), PyTraceMalloc_Untrack() and _PyTraceMalloc_TraceRef() now check tracemalloc_config.tracing after calling TABLES_LOCK().

_PyTraceMalloc_Stop() now protects more code with TABLES_LOCK(), especially setting tracemalloc_config.tracing to 1.

Add a test using PyTraceMalloc_Track() to test tracemalloc.stop() race condition.

Call _PyTraceMalloc_Init() at Python startup.

(cherry picked from commit 6b47499)

…n#128897)

tracemalloc_alloc(), tracemalloc_realloc(), PyTraceMalloc_Track(),
PyTraceMalloc_Untrack() and _PyTraceMalloc_TraceRef() now check
tracemalloc_config.tracing after calling TABLES_LOCK().

_PyTraceMalloc_Stop() now protects more code with TABLES_LOCK(),
especially setting tracemalloc_config.tracing to 1.

Add a test using PyTraceMalloc_Track() to test tracemalloc.stop()
race condition.

Call _PyTraceMalloc_Init() at Python startup.

(cherry picked from commit 6b47499)
@vstinner
Copy link
Member Author

I tested manually my change on FreeBSD with Python built in release mode. I ran test_tracemalloc_track_race() 1,000x in a loop (using -F option) and it doesn't crash.

@vstinner vstinner enabled auto-merge (squash) January 19, 2025 13:12
@vstinner vstinner merged commit 6df22cb into python:3.12 Jan 19, 2025
30 checks passed
@vstinner vstinner deleted the tracemalloc_stop12 branch January 19, 2025 13:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant