madsim-rs / madsim

Magical Deterministic Simulator for distributed systems in Rust.
Apache License 2.0
618 stars 41 forks source link

feat: add tokio::Runtime::enter #175

Closed TennyZhuang closed 8 months ago

TennyZhuang commented 8 months ago

https://docs.rs/tokio/latest/tokio/runtime/struct.Runtime.html#method.enter

TennyZhuang commented 8 months ago

It seems that we can madsim::spawn without any initialization operations? So I guess no-op here is OK.

wangrunji0408 commented 8 months ago

Wait a moment. I found a problem. When a Runtime is dropped, all tasks spawned in it should also be cancelled. Therefore, madsim::spawn should find the current runtime first and store the task in it. However, this is not the case now, which means that if we create a runtime R, spawn a task A by R.spawn(), and then spawn a new task B in A using madsim::spawn, B will not be dropped along with runtime R. This is a bug that should definitely be fixed. Would you prefer to fix it in this PR or enable this API first and then fix the problem later?

TennyZhuang commented 8 months ago

Wait a moment. I found a problem. When a Runtime is dropped, all tasks spawned in it should also be cancelled. Therefore, madsim::spawn should find the current runtime first and store the task in it. However, this is not the case now, which means that if we create a runtime R, spawn a task A by R.spawn(), and then spawn a new task B in A using madsim::spawn, B will not be dropped along with runtime R. This is a bug that should definitely be fixed. Would you prefer to fix it in this PR or enable this API first and then fix the problem later?

It seems that the bug exists even without the PR?

wangrunji0408 commented 8 months ago

Yes. Let's fix it later.

TennyZhuang commented 8 months ago

Yes. Let's fix it later.

Can you merge the PR and release a new version?

wangrunji0408 commented 8 months ago

Sorry. forgot this 🤡

wangrunji0408 commented 8 months ago

published as v0.2.24