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

tokio-macros 1.4.0 blocks usage of tokio::task::block_in_place even in multi_thread flavored tests #4140

Closed
tadman opened this issue Sep 30, 2021 · 4 comments · Fixed by #4142
Labels
A-tokio Area: The main tokio crate A-tokio-macros Area: The tokio-macros crate C-bug Category: This is a bug. I-crash Problems and improvements related to program crashes/panics.

Comments

@tadman
Copy link

tadman commented Sep 30, 2021

Version

tm_block_in_place v0.1.0
├── tokio v1.12.0
│   ├── bytes v1.1.0
│   ├── libc v0.2.103
│   ├── memchr v2.4.1
│   ├── mio v0.7.13
│   │   ├── libc v0.2.103
│   │   └── log v0.4.14
│   │       └── cfg-if v1.0.0
│   ├── num_cpus v1.13.0
│   │   └── libc v0.2.103
│   ├── once_cell v1.8.0
│   ├── parking_lot v0.11.2
│   │   ├── instant v0.1.11
│   │   │   └── cfg-if v1.0.0
│   │   ├── lock_api v0.4.5
│   │   │   └── scopeguard v1.1.0
│   │   └── parking_lot_core v0.8.5
│   │       ├── cfg-if v1.0.0
│   │       ├── instant v0.1.11 (*)
│   │       ├── libc v0.2.103
│   │       └── smallvec v1.7.0
│   ├── pin-project-lite v0.2.7
│   ├── signal-hook-registry v1.4.0
│   │   └── libc v0.2.103
│   └── tokio-macros v1.3.0 (proc-macro)
│       ├── proc-macro2 v1.0.29
│       │   └── unicode-xid v0.2.2
│       ├── quote v1.0.9
│       │   └── proc-macro2 v1.0.29 (*)
│       └── syn v1.0.77
│           ├── proc-macro2 v1.0.29 (*)
│           ├── quote v1.0.9 (*)
│           └── unicode-xid v0.2.2
│   [build-dependencies]
│   └── autocfg v1.0.1
└── tokio-macros v1.4.0 (proc-macro) (*)

Platform

Reproduced on both macOS (11.15.2) and Linux:

Darwin hammer 20.6.0 Darwin Kernel Version 20.6.0: Wed Jun 23 00:26:27 PDT 2021; root:xnu-7195.141.2~5/RELEASE_ARM64_T8101 arm64
Linux xa 5.4.0-81-generic #91-Ubuntu SMP Thu Jul 15 19:09:17 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux

Description

Under 1.3.0 and prior versions of tokio-macros the tests execute correctly. WIth 1.4.0 the following result occurs:

thread 'tests::dont_panic' panicked at 'can call blocking only when running on the multi-threaded runtime', .../.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.12.0/src/runtime/thread_pool/worker.rs:286:21
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

Even though this is explicitly within a "multi_thread" runtime.

This is caused by any use of tokio::task::block_in_place().

Example test that fails:

#[cfg(test)]
mod tests {
    #[tokio::test(flavor = "multi_thread", worker_threads = 2)]
    async fn dont_panic() {
        tokio::task::block_in_place(move || { });
    }
}

This executes correctly in 1.3.0, but fails in 1.4.0. There should be multiple threads available as per the test definition, but this does not appear to be the case.

@tadman tadman added A-tokio Area: The main tokio crate C-bug Category: This is a bug. labels Sep 30, 2021
@Noah-Kennedy Noah-Kennedy added A-tokio-macros Area: The tokio-macros crate I-crash Problems and improvements related to program crashes/panics. P-high labels Sep 30, 2021
@Noah-Kennedy
Copy link
Contributor

I suspect #4027 may be to blame.

@tadman
Copy link
Author

tadman commented Sep 30, 2021

It's worth noting that this doesn't just happen in tests, it seems to impact any use of the #[tokio] macros, but it seems super easy to reproduce within tests. I'm also seeing it within a main function like:

#[tokio::main(worker_threads = 2)]
async fn main() {
    tokio::task::block_in_place(move || { });
}

I found this while trying to figure out why tokio-diesel began to malfunction.

The project pivoted to block_in_place for a number of reasons expressed here.

@Noah-Kennedy
Copy link
Contributor

I ran a bisect, #4027 introduced this issue.

@Darksonn
Copy link
Contributor

Thanks, I am yanking tokio-macros 1.4.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-tokio Area: The main tokio crate A-tokio-macros Area: The tokio-macros crate C-bug Category: This is a bug. I-crash Problems and improvements related to program crashes/panics.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants