Oneshot channel deadlock on async runtime#21916
Draft
nameexhaustion wants to merge 3 commits intopola-rs:mainfrom
Draft
Oneshot channel deadlock on async runtime#21916nameexhaustion wants to merge 3 commits intopola-rs:mainfrom
nameexhaustion wants to merge 3 commits intopola-rs:mainfrom
Conversation
ddf5907 to
d0914d4
Compare
90ceb7b to
e9fce55
Compare
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.
Description
Using tokio's oneshot channel on our async runtime can lead to an intermittent deadlock. Tested on macOS 14.6.1 / Apple M3 Pro.
As an alternative, we can currently use the
connectorinstead.Steps to reproduce
make build-releasedbg!in this branch:crates/polars-stream/src/nodes/io_sources/multi_file_reader/reader_pipelines/generic.rs:505:17crates/polars-stream/src/nodes/io_sources/parquet_reader/mod.rs:166:13async_executor::spawncrates/polars-stream/src/nodes/io_sources/multi_file_reader/reader_pipelines/generic.rs:509:17The script runs an infinite loop, however the output should eventually stop and look something like this:
It should show that for the latest scan source (3 in the above case), only 2 lines of
dbg!are printed - the one from after a value is sent, and the one from before the receiver is awaited. But somehow theawaiton the receiver is not completing even though a value is sent.This branch also uses an updated
TracedAwait, if we setPOLARS_AWAIT_TIMEOUT_REPOLL=1, the output from the script should resume after printingrepolling in 2 seconds. It is as though we have missed a task wakeup notification.Notes
make build-release)POLARS_MAX_THREADS=1Waker oddness
Tokio's oneshot channel has a mechanism by which the receiver avoids cloning the context waker if it determines that it already has a waker from a previous poll that wakes the same task using
will_wake. If we patch this to instead always replace the waker, the deadlock will not occur - tokio-rs/tokio@master...nameexhaustion:tokio:tokio-1.43-will-wake.