Skip to content
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

rustc panics when compiling code that uses tokio's LocalSet #68109

Closed
Alovchin91 opened this issue Jan 11, 2020 · 8 comments
Closed

rustc panics when compiling code that uses tokio's LocalSet #68109

Alovchin91 opened this issue Jan 11, 2020 · 8 comments
Assignees
Labels
A-async-await Area: Async & Await AsyncAwait-Triaged Async-await issues that have been triaged during a working group meeting. C-bug Category: This is a bug. E-needs-mcve Call for participation: This issue has a repro, but needs a Minimal Complete and Verifiable Example E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ P-high High priority T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. WG-async Working group: Async & await

Comments

@Alovchin91
Copy link

Alovchin91 commented Jan 11, 2020

Compiler panics when compiling the following code that uses tokio's LocalSet:

#[tokio::main]
async fn main() {
    tokio::spawn(async move {
        let local = tokio::task::LocalSet::new();
        local.run_until(async { })
    }).await
}

--- or ---

#[tokio::main]
async fn main() {
    tokio::spawn({
        let local = tokio::task::LocalSet::new();
        local.run_until(async {})
    }).await
}

Panic message is as follows:

➜ RUST_BACKTRACE=full cargo build --verbose
       ...
       Fresh tokio v0.2.9
   Compiling rust-bug v0.1.0 (/tmp/rust-bug)
     Running `rustc --edition=2018 --crate-name rust_bug src/main.rs --error-format=json --json=diagnostic-rendered-ansi --crate-type bin --emit=dep-info,link -C debuginfo=2 -C metadata=b5f969b2f9a6a1a5 -C extra-filename=-b5f969b2f9a6a1a5 --out-dir /tmp/rust-bug/target/debug/deps -C incremental=/tmp/rust-bug/target/debug/incremental -L dependency=/tmp/rust-bug/target/debug/deps --extern tokio=/tmp/rust-bug/target/debug/deps/libtokio-e472db2be190b401.rlib`
thread 'rustc' panicked at 'called `Option::unwrap()` on a `None` value', src/libcore/option.rs:378:21
stack backtrace:
   0:        0x104e46b75 - <unknown>
   1:        0x104e7dcc0 - <unknown>
             ...
 101:        0x104e59a6e - <unknown>
 102:     0x7fff6bb56e65 - <unknown>

error: internal compiler error: unexpected panic

note: the compiler unexpectedly panicked. this is a bug.

note: we would appreciate a bug report: https://github.com/rust-lang/rust/blob/master/CONTRIBUTING.md#bug-reports

note: rustc 1.40.0 (73528e339 2019-12-16) running on x86_64-apple-darwin

note: compiler flags: -C debuginfo=2 -C incremental --crate-type bin

note: some of the compiler flags provided by cargo are hidden

query stack during panic:
#0 [typeck_tables_of] processing `tokio::task::local::LocalSet::run_until`
#1 [typeck_tables_of] processing `tokio::task::local::LocalSet::run_until::{{closure}}#0`
#2 [typeck_tables_of] processing `main`
#3 [typeck_tables_of] processing `main::{{closure}}#0`
#4 [type_of] processing `main::{{closure}}#0`
#5 [collect_mod_item_types] collecting item types in top-level module
#6 [analysis] running analysis passes on this crate
end of query stack
error: could not compile `rust-bug`.

Caused by:
  process didn't exit successfully: `rustc --edition=2018 --crate-name rust_bug src/main.rs --error-format=json --json=diagnostic-rendered-ansi --crate-type bin --emit=dep-info,link -C debuginfo=2 -C metadata=b5f969b2f9a6a1a5 -C extra-filename=-b5f969b2f9a6a1a5 --out-dir /tmp/rust-bug/target/debug/deps -C incremental=/tmp/rust-bug/target/debug/incremental -L dependency=/tmp/rust-bug/target/debug/deps --extern tokio=/tmp/rust-bug/target/debug/deps/libtokio-e472db2be190b401.rlib` (exit code: 101)

Dependencies:

[dependencies]
tokio = { version = "0.2.9", features = ["full"] }

Sample:

rust-bug.zip

@Centril Centril added A-async-await Area: Async & Await E-needs-mcve Call for participation: This issue has a repro, but needs a Minimal Complete and Verifiable Example I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. I-nominated labels Jan 11, 2020
@JohnTitor JohnTitor added the C-bug Category: This is a bug. label Jan 12, 2020
@hellow554
Copy link
Contributor

Does not occur on beta or nightly, although the error message could be improved:

error[E0277]: `std::rc::Rc<tokio::task::local::Scheduler>` cannot be sent between threads safely
   --> src/main.rs:3:5
    |
3   |     tokio::spawn(async move {
    |     ^^^^^^^^^^^^ `std::rc::Rc<tokio::task::local::Scheduler>` cannot be sent between threads safely
    | 
   ::: /home/op/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-0.2.9/src/task/spawn.rs:124:20
    |
124 |         T::Output: Send + 'static,
    |                    ---- required by this bound in `tokio::task::spawn::spawn`
    |
    = help: within `impl std::future::Future`, the trait `std::marker::Send` is not implemented for `std::rc::Rc<tokio::task::local::Scheduler>`
    = note: required because it appears within the type `for<'r> {&'r tokio::task::local::LocalSet, impl std::future::Future, std::rc::Rc<tokio::task::local::Scheduler>, tokio::task::local::LocalFuture<impl std::future::Future>, tokio::task::local::LocalFuture<impl std::future::Future>, tokio::task::local::LocalFuture<impl std::future::Future>, ()}`
    = note: required because it appears within the type `[static generator@DefId(15:7135 ~ tokio[52aa]::task[0]::local[0]::{{impl}}[0]::run_until[0]::{{closure}}[0]) 0:&tokio::task::local::LocalSet, 1:impl std::future::Future for<'r> {&'r tokio::task::local::LocalSet, impl std::future::Future, std::rc::Rc<tokio::task::local::Scheduler>, tokio::task::local::LocalFuture<impl std::future::Future>, tokio::task::local::LocalFuture<impl std::future::Future>, tokio::task::local::LocalFuture<impl std::future::Future>, ()}]`
    = note: required because it appears within the type `std::future::GenFuture<[static generator@DefId(15:7135 ~ tokio[52aa]::task[0]::local[0]::{{impl}}[0]::run_until[0]::{{closure}}[0]) 0:&tokio::task::local::LocalSet, 1:impl std::future::Future for<'r> {&'r tokio::task::local::LocalSet, impl std::future::Future, std::rc::Rc<tokio::task::local::Scheduler>, tokio::task::local::LocalFuture<impl std::future::Future>, tokio::task::local::LocalFuture<impl std::future::Future>, tokio::task::local::LocalFuture<impl std::future::Future>, ()}]>`
    = note: required because it appears within the type `impl std::future::Future`
    = note: required because it appears within the type `impl std::future::Future`

error[E0277]: `std::rc::Rc<tokio::task::local::Scheduler>` cannot be shared between threads safely
   --> src/main.rs:3:5
    |
3   |     tokio::spawn(async move {
    |     ^^^^^^^^^^^^ `std::rc::Rc<tokio::task::local::Scheduler>` cannot be shared between threads safely
    | 
   ::: /home/op/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-0.2.9/src/task/spawn.rs:124:20
    |
124 |         T::Output: Send + 'static,
    |                    ---- required by this bound in `tokio::task::spawn::spawn`
    |
    = help: within `tokio::task::local::LocalSet`, the trait `std::marker::Sync` is not implemented for `std::rc::Rc<tokio::task::local::Scheduler>`
    = note: required because it appears within the type `tokio::task::local::LocalSet`
    = note: required because of the requirements on the impl of `std::marker::Send` for `&tokio::task::local::LocalSet`
    = note: required because it appears within the type `[static generator@DefId(15:7135 ~ tokio[52aa]::task[0]::local[0]::{{impl}}[0]::run_until[0]::{{closure}}[0]) 0:&tokio::task::local::LocalSet, 1:impl std::future::Future for<'r> {&'r tokio::task::local::LocalSet, impl std::future::Future, std::rc::Rc<tokio::task::local::Scheduler>, tokio::task::local::LocalFuture<impl std::future::Future>, tokio::task::local::LocalFuture<impl std::future::Future>, tokio::task::local::LocalFuture<impl std::future::Future>, ()}]`
    = note: required because it appears within the type `std::future::GenFuture<[static generator@DefId(15:7135 ~ tokio[52aa]::task[0]::local[0]::{{impl}}[0]::run_until[0]::{{closure}}[0]) 0:&tokio::task::local::LocalSet, 1:impl std::future::Future for<'r> {&'r tokio::task::local::LocalSet, impl std::future::Future, std::rc::Rc<tokio::task::local::Scheduler>, tokio::task::local::LocalFuture<impl std::future::Future>, tokio::task::local::LocalFuture<impl std::future::Future>, tokio::task::local::LocalFuture<impl std::future::Future>, ()}]>`
    = note: required because it appears within the type `impl std::future::Future`
    = note: required because it appears within the type `impl std::future::Future`

error[E0308]: mismatched types
 --> src/main.rs:1:1
  |
1 | #[tokio::main]
  | ^^^^^^^^^^^^^^- help: try adding a semicolon: `;`
  | |
  | expected `()`, found enum `std::result::Result`
  |
  = note: expected unit type `()`
                  found enum `std::result::Result<impl std::future::Future, tokio::task::error::JoinError>`

error: aborting due to 3 previous errors

Some errors have detailed explanations: E0277, E0308.
For more information about an error, try `rustc --explain E0277`.
error: could not compile `rust-bug`.

@hellow554
Copy link
Contributor

Has been fixed in 41601a8 (maybe this was fixed by #67071?)

@nikomatsakis
Copy link
Contributor

This could use a regression test, but it's hard because we'd have to isolate it out from the tokio dependency.

@tmandry tmandry added AsyncAwait-Triaged Async-await issues that have been triaged during a working group meeting. E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. labels Jan 14, 2020
@gilescope
Copy link
Contributor

@rustbot claim

@pnkfelix
Copy link
Member

T-compiler triage: P-high, removing nomination label.

@pnkfelix pnkfelix added P-high High priority and removed I-nominated labels Jan 16, 2020
@dtolnay
Copy link
Member

dtolnay commented Jan 27, 2022

@rustbot release-assignment

@jackh726 jackh726 added the WG-async Working group: Async & await label Feb 3, 2022
@pnkfelix
Copy link
Member

@rustbot claim

@pnkfelix
Copy link
Member

I attempted to recreate the problem atop 1.40.0 stable.

I was not able to recreate the ICE.

Unfortunately the .zip file attached to the issue did not include a Cargo.lock file in it, so I cannot be totally sure that all the upstream dependencies that I am grabbing match that of the issue authro.

even more unfortunately, the raw stack trace has no symbols, and the assertion is just an "unwrap of None" assert. So the only contextual info we have is the query stack, and that isn't enough for me to identify what the problem might have been at that time.

(e.g. could it have been an incremental compilation bug? Its impossible to tell at this point.)

So, I'm sadly forced to close this as non-actionable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-async-await Area: Async & Await AsyncAwait-Triaged Async-await issues that have been triaged during a working group meeting. C-bug Category: This is a bug. E-needs-mcve Call for participation: This issue has a repro, but needs a Minimal Complete and Verifiable Example E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ P-high High priority T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. WG-async Working group: Async & await
Projects
None yet
Development

No branches or pull requests

10 participants