Repository navigation
fix(internal): fix crash at finalisation - #20081
KowalskiThomas wants to merge 5 commits into
Conversation
Codeowners resolved asResolved from the full PR diff against |
Circular import analysis
|
Dependency direction analysis
|
|
✅ All CI checks and tests passed. 🎉 All green!🧪 All tests passed 🔗 Commit SHA: 62222d5 | Docs | View more details | Give us feedback! |
BenchmarksBenchmark execution time: 2026-10-13 08:41:58 Comparing candidate commit 62222d5 in PR branch Found 0 performance improvements and 6 performance regressions! Performance is the same for 547 metrics, 10 unstable metrics, 7 known flaky benchmarks, 17 flaky benchmarks without significant changes.
|
P403n1x87
left a comment
There was a problem hiding this comment.
LGTM modulo open conversations
VianneyRuhlmann
left a comment
There was a problem hiding this comment.
LGTM, maybe add a regression test crashing for py<3.14 but that might be a bit complicated to setup
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
3790fa4 to
524b2e7
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 3790fa4574
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| let _ = py; // The GIL is held on entry, which PyEval_SaveThread requires. | ||
| let save = unsafe { ffi::PyEval_SaveThread() }; |
There was a problem hiding this comment.
Suspend PyO3 attachment state while releasing the GIL
Calling PyEval_SaveThread() directly leaves PyO3's thread-local attachment count indicating that this thread is still attached, unlike Python::detach. This is already unsafe for TraceExporterPy::send and the other byte-payload callers: their moved PyBackedBytes captures are destroyed when catch_unwind returns, before the GIL is restored, so PyO3 can perform the owner's Py_DECREF while believing the GIL is held. Preserve PyO3's suspension bookkeeping (or otherwise keep every Python-owned value alive until after restoration) to avoid refcount corruption or crashes during ordinary sends.
AGENTS.md reference: AGENTS.md:L135-L135
Useful? React with 👍 / 👎.
259c4ff to
9af8e79
Compare
9af8e79 to
62222d5
Compare
Description
This fixes a crash that can happen at interpreter finalisation before Python 3.14. Python 3.14 fixed this in python/cpython#87135 but previous versions are still sensitive to the issue. We fix it in the Python tracer by replicating python/cpython#105805, where threads trying to acquire the GIL at finalisation time are hanged rather than properly exited.
This happens because the exporter runs on a thread that is not joined at shutdown. (The PR fixes the bug for all native threads, not only the exporter.)