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

LocalSet drop impl panics when dropped with unfinished futures #1842

Closed
swlynch99 opened this issue Nov 27, 2019 · 2 comments · Fixed by #1843
Closed

LocalSet drop impl panics when dropped with unfinished futures #1842

swlynch99 opened this issue Nov 27, 2019 · 2 comments · Fixed by #1843
Labels
C-bug Category: This is a bug.

Comments

@swlynch99
Copy link

Version

cargo tree | grep tokio
└── tokio v0.2.1

Platform

uname -a
Darwin tw-mbp-slynch 18.7.0 Darwin Kernel Version 18.7.0: Sat Oct 12 00:02:19 PDT 2019; root:xnu-4903.278.12~1/RELEASE_X86_64 x86_64
rustc --version
rustc 1.39.0 (4560ea788 2019-11-04

Description

The drop impl for tokio::task::LocalSet panics with

internal error: entered unreachable code: tasks should only be completed locally

when it is dropped while it still contains an incomplete future. Instead, I would expect this to just drop all the incomplete futures and continue normally.

The following code triggers this issue

use std::time::Duration;

use tokio::time::delay_for;
use tokio::runtime::Builder;
use tokio::task::LocalSet;

async fn run_forever() {
    loop {
        delay_for(Duration::from_secs(3600)).await;
    }
}

async fn run_fast() {
    delay_for(Duration::from_millis(10)).await;
}

fn main() -> std::io::Result<()> {
    let mut rt = Builder::new()
        .enable_time()
        .basic_scheduler()
        .build()?;

    let set = LocalSet::new();
    set.spawn_local(run_forever());
    set.block_on(&mut rt, run_fast());

    Ok(())
}
Cargo.toml
[package]
name = "mcve"
version = "0.1.0"
edition = "2018"

[dependencies.tokio]
version="0.2.1"
features=[ "time", "rt-core", "rt-util" ]

Stack Trace

thread 'main' panicked at 'internal error: entered unreachable code: tasks should only be completed locally', /Users/slynch/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-0.2.1/src/task/local.rs:349:9
stack backtrace:
   0:        0x10b53cf65 - std::sys_common::at_exit_imp::push::hbcb9accb9aed3616
   1:        0x10b554be0 - core::fmt::ArgumentV1::show_usize::h5612effbabb12159
   2:        0x10b53b2fb - std::io::Write::write_fmt::h7bd7b6fe8b47c5fb
   3:        0x10b53eb7a - std::panicking::default_hook::{{closure}}::heee79636c241547c
   4:        0x10b53e885 - std::panicking::default_hook::hfcbd07059d15441e
   5:        0x10b53f247 - <std::panicking::begin_panic::PanicPayload<A> as core::panic::BoxMeUp>::get::h2b8b0a58863fcf2c
   6:        0x10b53edbd - std::panicking::continue_panic_fmt::h0e74ab2b215a1401
   7:        0x10b55804e - std::thread::local::fast::Key<T>::try_initialize::hcdc98eb893033f5a
   8:        0x10b526a2f - <tokio::task::local::Scheduler as tokio::task::Schedule>::release::h354af237f36f45f0
                               at /Users/slynch/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-0.2.1/src/task/local.rs:349
   9:        0x10b501141 - tokio::task::harness::Harness<T,S>::do_cancel::h34aab5a1c9fefa0e
                               at /Users/slynch/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-0.2.1/src/task/harness.rs:391
  10:        0x10b5008bf - tokio::task::harness::Harness<T,S>::cancel::h5dc98c6a2e9acf9f
                               at /Users/slynch/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-0.2.1/src/task/harness.rs:342
  11:        0x10b4fe012 - tokio::task::raw::cancel::h713e03278d359f08
                               at /Users/slynch/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-0.2.1/src/task/raw.rs:196
  12:        0x10b51a4de - tokio::task::list::OwnedList<T>::shutdown::h819bd7f227889e20
                               at /Users/slynch/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-0.2.1/src/task/list.rs:68
  13:        0x10b527666 - <tokio::task::local::Scheduler as core::ops::drop::Drop>::drop::h38a36f038ca65249
                               at /Users/slynch/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-0.2.1/src/task/local.rs:490
  14:        0x10b505d55 - core::ptr::real_drop_in_place::hce300fa65c00fc82
                               at /rustc/4560ea788cb760f0a34127156c78e2552949f734/src/libcore/ptr/mod.rs:175
  15:        0x10b5057ae - core::ptr::real_drop_in_place::h91d23830a1679dd7
                               at /rustc/4560ea788cb760f0a34127156c78e2552949f734/src/libcore/ptr/mod.rs:175
  16:        0x10b4fc34e - core::ptr::drop_in_place::h9fbdc1f16152cc97
                               at /rustc/4560ea788cb760f0a34127156c78e2552949f734/src/libcore/ptr/mod.rs:165
  17:        0x10b4fc34e - <alloc::rc::Rc<T> as core::ops::drop::Drop>::drop::h2a5f174f42f1e30a
                               at /rustc/4560ea788cb760f0a34127156c78e2552949f734/src/liballoc/rc.rs:1098
  18:        0x10b504f75 - core::ptr::real_drop_in_place::h083d13dc9290de0b
                               at /rustc/4560ea788cb760f0a34127156c78e2552949f734/src/libcore/ptr/mod.rs:175
  19:        0x10b506075 - core::ptr::real_drop_in_place::heb6700c1e84481fd
                               at /rustc/4560ea788cb760f0a34127156c78e2552949f734/src/libcore/ptr/mod.rs:175
  20:        0x10b5075e2 - mcve::main::hf863556eb750bbdf
                               at src/main.rs:31
  21:        0x10b4faf76 - std::rt::lang_start::{{closure}}::hf2f3af7d2e40962c
                               at /rustc/4560ea788cb760f0a34127156c78e2552949f734/src/libstd/rt.rs:64
  22:        0x10b53ec98 - std::panicking::try::do_call::ha1a4587e2a4eb439
  23:        0x10b54068f - panic_unwind::dwarf::eh::read_encoded_pointer::h8a85bd7bb8b1ba5e
  24:        0x10b53f5ee - <std::panicking::begin_panic::PanicPayload<A> as core::panic::BoxMeUp>::get::h2b8b0a58863fcf2c
  25:        0x10b4faf52 - std::rt::lang_start::h1808cc0130c38463
                               at /rustc/4560ea788cb760f0a34127156c78e2552949f734/src/libstd/rt.rs:64
  26:        0x10b5076c2 - mcve::main::hf863556eb750bbdf
@hawkw
Copy link
Member

hawkw commented Nov 27, 2019

Thanks for the report! I'll take a look at fixing that.

hawkw added a commit that referenced this issue Nov 27, 2019
Signed-off-by: Eliza Weisman <eliza@buoyant.io>
hawkw added a commit that referenced this issue Nov 27, 2019
it turns out that the `Scheduler::release` method on `LocalSet`'s
`Scheduler` *is* called, when the  `Scheduler` is dropped with tasks
still running. Currently, that method is `unreachable!`, which means
that dropping a `LocalSet` with tasks running will panic.

This commit fixes the panic, by pushing released tasks to
`pending_drop`. This is the same as `BasicScheduler`.

Fixes #1842

Signed-off-by: Eliza Weisman <eliza@buoyant.io>
@hawkw
Copy link
Member

hawkw commented Nov 27, 2019

PR #1843 should fix this. Thanks again for reporting!

@hawkw hawkw added the C-bug Category: This is a bug. label Nov 27, 2019
carllerche pushed a commit that referenced this issue Nov 27, 2019
It turns out that the `Scheduler::release` method on `LocalSet`'s
`Scheduler` *is* called, when the  `Scheduler` is dropped with tasks
still running. Currently, that method is `unreachable!`, which means
that dropping a `LocalSet` with tasks running will panic.

This commit fixes the panic, by pushing released tasks to
`pending_drop`. This is the same as `BasicScheduler`.

Fixes #1842
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants