Skip to content

Drop replaced tracing callbacks outside locks - #9612

Merged
youknowone merged 2 commits into
RustPython:mainfrom
youknowdot:fix/tracing-callback-release-lock-20261103
Nov 6, 2026
Merged

youknowone merged 2 commits into
RustPython:mainfrom
youknowdot:fix/tracing-callback-release-lock-20261103

Conversation

@youknowdot

Copy link
Copy Markdown
Contributor

Summary

Retain replaced trace and profile callbacks until the current-thread or all-thread updates are complete and the associated locks and VM borrows are released. A callback's finalizer can reenter these APIs; dropping a last reference while holding a callback or thread-registry mutex can otherwise deadlock.

For all-thread setters, reserve storage for the old slot callbacks before changing global or slot state. On allocation failure, release the registry lock before constructing MemoryError and leave tracing state unchanged. The lock order follows the existing thread-slot initialization path.

Validation

  • Independently source-reviewed for current/all-thread state ordering, callback ownership, reentrancy, unwind and allocation-failure handling, lock order, threading/nonthreading configurations, and CPython 3.15's deferred old-callback decrefs.
  • prek run --files crates/vm/src/stdlib/sys.rs, normal commit hooks, and git diff --check passed.
  • Native RustPython compilation and execution were not run locally; hosted CI is required. Existing test_threading cases cover normal all-thread trace/profile updates, but no existing test identified directly covers finalizer reentry.

Scope

This is a narrow callback-lifetime fix. Existing all-thread dispatch and stop-the-world differences from CPython remain outside this change. No Lib or test files were modified.

Retain old trace and profile callbacks until all thread slots and VM state are updated and locks are released. Reserve all-thread storage before mutation so allocation failure leaves state unchanged.

Assisted-by: OpenAI Codex:model version not exposed
@coderabbitai

coderabbitai Bot commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

Caution

Review failed

The pull request is closed.

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@youknowone
youknowone marked this pull request as ready for review November 6, 2026 12:10
@chatgpt-codex-connector

Copy link
Copy Markdown
Codex Review Summary: ❌ Failed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ❌ Failed 2026-11-06T12:10:55.187585Z
We couldn’t complete this review. Comment @codex review to try again.
53da77d Draft marked ready
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@youknowone
youknowone merged commit 32be309 into RustPython:main Nov 6, 2026
24 of 28 checks passed
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.

2 participants