-
-
Notifications
You must be signed in to change notification settings - Fork 14.8k
pthread_exit crashes on threads created by std::thread::spawn in 1.84, not 1.83, breaking pyo3-log #135929
Copy link
Copy link
Closed
Labels
A-threadArea: `std::thread`Area: `std::thread`C-bugCategory: This is a bug.Category: This is a bug.S-has-bisectionStatus: A bisection has been found for this issueStatus: A bisection has been found for this issueS-has-mcveStatus: A Minimal Complete and Verifiable Example has been found for this issueStatus: A Minimal Complete and Verifiable Example has been found for this issueT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.T-libsRelevant to the library team, which will review and decide on the PR/issue.Relevant to the library team, which will review and decide on the PR/issue.
Metadata
Metadata
Assignees
Labels
A-threadArea: `std::thread`Area: `std::thread`C-bugCategory: This is a bug.Category: This is a bug.S-has-bisectionStatus: A bisection has been found for this issueStatus: A bisection has been found for this issueS-has-mcveStatus: A Minimal Complete and Verifiable Example has been found for this issueStatus: A Minimal Complete and Verifiable Example has been found for this issueT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.T-libsRelevant to the library team, which will review and decide on the PR/issue.Relevant to the library team, which will review and decide on the PR/issue.
Type
Fields
Give feedbackNo fields configured for issues without a type.
Meta
Tested on Ubuntu 24.04 and Amazon Linux 2, x86_64.
Workaround to the production problem
In your Cargo.toml that is compiling your Python module, set
This prevents the 1.84 crashes.
However, there is still UB going on even with this setting.
The Production Problem
The crate pyo3-log installs a bridge that makes log functions call into Python. This means that all calls to
logging::info!etc will take the GIL.Python has a stage during interpreter shutdown where attempts to take the GIL will cause a
pthread_exit. Python 3.14 (still Alpha today, targeted to be released by the end of this year) will change this in python/cpython#87135 - but that will take some time to reach people.This means that if you have a Python program that uses a Rust library and pyo3-log, that spawning a Rust thread, that is calling
logging::info!in a way unsynchronized with interpreter exit, you'll have unpredicatable crashes in 1.84.Minified Program
This program:
when compiled with the following options
crashes with this confusing error
This crash happens:
When using
-C panic=unwindinstead, on all versions of the compiler, you get this error:I seen the claim in Zulip (https://rust-lang.zulipchat.com/#narrow/channel/122651-general/topic/pthread_exit.20from.20a.20Rust-spawned.20thread) that this is undefined behavior, but I'll rather not break pyo3-log