-
Notifications
You must be signed in to change notification settings - Fork 48
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Encountered there is no reactor running, must be called from the context of a Madsim runtime
while spawning task in drop
impl
#228
Comments
This seems to be the most related explanation: #182 (comment)
As the bug only happens in |
Kindly ask for assistance from the project author @wangrunji0408 |
After doing some tracing, here's some further finding. The dropped task does not run on any executor node, so we don't see the attached (A side note, we can make the error messages more specific, rather than no runtime, we can say "task context not found", but perhaps this is inconsistent with tokio's errors.) |
In relation to this specific testcase:
The major difference is that we enter the runtime context per task in madsim/madsim/src/sim/task/mod.rs Lines 279 to 280 in b7dbec0
In tokio however, we always enter the runtime context when we block_on the runtime, so it will always be accessible by spawned tasks. The runtime context is not on a task level. Now consider that destructors for madsim/madsim/src/sim/task/mod.rs Line 315 in b7dbec0
Backtrace:
At this specific part, it is obvious that there is no task context entered, as it is only entered in L279-L280! So it clearly explains why there is no task context. Now the root cause is known, we need to decide how to solve it. |
By explicitly adding a madsim/madsim/src/sim/task/mod.rs Lines 269 to 271 in 9978cf0
Also we don't need a fake fn runtime_drop_bugen() {
#[derive(Debug)]
struct A;
impl Drop for A {
fn drop(&mut self) {
Handle::current().spawn(std::future::pending::<()>());
}
}
let a = A;
let runtime = madsim::runtime::Runtime::new();
runtime.block_on(async move {
let join_handle = madsim::task::spawn(async move { drop(a) });
join_handle.abort();
let err = join_handle.await.unwrap_err();
assert!(err.is_cancelled());
})
} |
Can we simply call |
This comment was marked as resolved.
This comment was marked as resolved.
See: #231 for a solution by @BugenZhao. Bugen took #228 (comment) further, and found that it's actually triggered inside the block which handles cancelled / killed nodes (#231 (comment)). We can abort the future since the node was killed or the task itself was cancelled. Importantly, it also ensures that Runnable will not be dropped without a task context, if it has a |
I encountered the following error message in this branch: risingwavelabs/risingwave#18795, in its main-cron ci workflow.
recovery-streaming-4.log
This happens when running a forked version of sqlx with
madsim-tokio 0.2.30
as its dependency, to overridetokio
.The origin of the panic is here: https://github.com/kwannoel/sqlx/blob/15ee4ba0eedc269540e42c6b4437c10de7325ed7/sqlx-core/src/pool/connection.rs#L166-L171:
This calls
rt::spawn
https://github.com/kwannoel/sqlx/blob/15ee4ba0eedc269540e42c6b4437c10de7325ed7/sqlx-core/src/rt/mod.rs#L61-L78:That calls:
madsim/madsim/src/sim/task/mod.rs
Lines 658 to 665 in b7dbec0
Which calls:
madsim/madsim/src/sim/task/mod.rs
Lines 585 to 592 in b7dbec0
And finally calls:
madsim/madsim/src/sim/runtime/context.rs
Lines 26 to 28 in b7dbec0
It then panics, since there's no current task.
My modification of
try_current
did not manage to fix it #227. Even if we modifiedtry_current
to properly check the task context, it will still be missing and just return an error instead of panicking. So we will be unable to spawn a thread to run the future still.I realize it's quite similar to existing issues in madsim, specifically when spawn is called during a
drop
, similar to #182. So I'm trying to understand if this is a known problem, and if so, what is the exact root cause.Reproducible example: #229
A list of related issues I found:
tokio::runtime::Runtime::enter
implementation #179tokio::runtime::Handle
#213Thanks in advance for your advice 🙏
The text was updated successfully, but these errors were encountered: