tokio-rs / tokio

A runtime for writing reliable asynchronous applications with Rust. Provides I/O, networking, scheduling, timers, ...
https://tokio.rs
MIT License
27.15k stars 2.49k forks source link

Tokio: thread '<unamed>' panicked when SIGINT #5776

Open lauti7 opened 1 year ago

lauti7 commented 1 year ago

Version

│       │   │   ├── tokio v1.28.1
│       │   │   │   └── tokio-macros v2.1.0 (proc-macro)
│       │   │   ├── tokio-util v0.7.8
│       │   │   │   ├── tokio v1.28.1 (*)
│       │   │   ├── tokio v1.28.1 (*)
│       │   │   ├── tokio v1.28.1 (*)
│       │   │   └── tokio-native-tls v0.3.1
│       │   │       └── tokio v1.28.1 (*)
│       │   ├── tokio v1.28.1 (*)
│       │   ├── tokio-native-tls v0.3.1 (*)
│       ├── tokio v1.28.1 (*)
│       ├── tokio-stream v0.1.14
│       │   └── tokio v1.28.1 (*)
│       ├── tokio-util v0.6.10
│       │   └── tokio v1.28.1 (*)
│           ├── tokio v1.28.1 (*)
│   └── tokio v1.28.1 (*)
│   ├── tokio v1.28.1 (*)
│   ├── tokio-tungstenite v0.18.0
│   │   ├── tokio v1.28.1 (*)
│   │   ├── tokio-native-tls v0.3.1 (*)
│   ├── tokio-util v0.7.8 (*)
│       ├── tokio v1.28.1 (*)
│       ├── tokio-stream v0.1.14 (*)
│       ├── tokio-tungstenite v0.18.0 (*)
│       ├── tokio-util v0.7.8 (*)
├── tokio v1.28.1 (*)
│   └── tokio v1.28.1 (*)
│   │   │   ├── tokio v1.28.1 (*)
│   │   │   └── tokio-native-tls v0.3.1 (*)
│   │   ├── tokio-stream v0.1.14 (*)
└── tokio v1.28.1 (*)
│   │   │   └── tokio v1.28.1 (*)
│   │   └── tokio v1.28.1 (*)
│       │   ├── tokio v1.28.1 (*)
│       │   └── tokio-util v0.7.8 (*)
│       ├── tokio v1.28.1 (*)
│       ├── tokio-util v0.7.8 (*)
└── tokio v1.28.1 (*)
│   │   ├── tokio v1.28.1 (*)
│   │   ├── tokio-util v0.7.8 (*)
│   │   ├── tokio v1.28.1 (*)
│   │   ├── tokio-util v0.7.8 (*)
│   │   ├── tokio v1.28.1 (*)
│   ├── tokio v1.28.1 (*)
│   └── tokio v1.28.1 (*)
├── tokio v1.28.1 (*)

Platform

Darwin Lautaros-MacBook-Pro.local 22.4.0 Darwin Kernel Version 22.4.0: Mon Mar  6 20:59:28 PST 2023; root:xnu-8796.101.5~3/RELEASE_ARM64_T6000 arm64

Description Hi, I'm opening up this issue to seek some help or an explanation for an error message I'm getting when running an Actix server with Tokio runtime and some Tokio spawned tasks.

The error is this:

thread '<unnamed>' panicked at 'A Tokio 1.x context was found, but it is being shutdown.', ~/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.27.0/src/runtime/time/entry.rs:553:13

Also, it seems to be intermittent. Sometimes happens when SIGINT, and other times doesn't.

I'd like to know what this error is related to and why the panic is provoked or maybe if I'm misusing something.

Darksonn commented 1 year ago

You can get that error if the runtime is shutting down.

The runtime shuts down when it goes out of scope, or for the tokio::main macro, when you return from main.

lauti7 commented 1 year ago

@Darksonn Thx for your quick response. So based on what u said, is there no way to avoid that panic? Is it not something that I should be worried about?

Darksonn commented 1 year ago

In general, the only way to avoid it is to make sure that the tasks have exited before you start the shutdown process.

lauti7 commented 1 year ago

Besides awaiting every task because I think I'm actually doing that, Is there any other way to assure that?