Repository navigation
rust(bug): fix python bindings segfault - #804
Merged
Merged
Conversation
tsift
previously approved these changes
Sep 29, 2026
tsift
approved these changes
Sep 29, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
rust(fix): stop the sift-stream-bindings tokio runtime before python exit
Relevant issues:
future_into_pycan call a closedasyncioloop during cancellation PyO3/pyo3-async-runtimes#90Problem
User reported segfault. Happens consistently in the
tokio-rt-workerthread. Happens when futures finishon the
tokioside but Python interpreter already shut down.Fix
The bindings now own their tokio runtime (
src/runtime.rs) and plug it intopyo3_async_runtimes::generic, so task locals, cancellation, and future resolution are unchanged.All sixteen
future_into_pycall sites route through it.shutdown(timeout=5.0)stops the runtime and joins its threads with the GIL released. The module registers it withatexitat import, so a normal interpreter exit always runs it while the interpreter is still intact. It can also be called directly, for example beforeos._exit().is_shut_down()reports whether it has run. Calls that need the runtime afterwards raiseRuntimeErrorinstead of crashing.sift-stream-workerso future crash logs identify them.Verification
User provided a repro script which was used for verification.
Linux container (Debian 13, aarch64, CPython 3.11.16, glibc 2.41), running the user's repro script unchanged:
cargo clippy --all-targets -D warningsclean. Generated.pyistub unchanged.Releases
sift-stream-bindings0.5.1 to 0.5.2, changelog entry under Unreleased inrust/CHANGELOG.md.