telegram-bot icon indicating copy to clipboard operation
telegram-bot copied to clipboard

Example poll.rs: thread 'main' panicked at 'there is no timer running, must be called from the context of a Tokio 0.2.x runtime'

Open robertpauson opened this issue 2 years ago • 5 comments

My Cargo.toml:

[package]
name = "tb"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[features]
openssl = ["hyper-tls"]
rustls = ["hyper-rustls"]
default = ["openssl"]

[dependencies]
bytes = "1.0.1"
tokio = { version = "1.2", features = ["full"]}

tracing = "0.1.23"
tracing-futures = "0.2"
multipart = { version = "0.17", default-features = false, features = ["client"] }

hyper = { version = "0.14", features = ["client", "http1"] }
hyper-tls = { version = "0.5", optional = true  }
futures = "0.3"
hyper-rustls = { version = "0.22", optional = true }
telegram-bot = "0.8.0"

[dev-dependencies]
tracing-subscriber = "0.2.15"
tokio = { version = "1.2", features = ["full"] }

robertpauson avatar Dec 04 '22 12:12 robertpauson

Are you using an async tokio::main main as an entry point?

ryanhossain9797 avatar Dec 04 '22 12:12 ryanhossain9797

yes of course same as in example


#[tokio::main]
async fn main() -> Result<(), Error> {

robertpauson avatar Dec 04 '22 13:12 robertpauson

Same problem for me, here's my Cargo.toml:

[package]
name = "telegram-bot-sample"
version = "0.1.0"
edition = "2021"

[dependencies]
anyhow = "1.0"
tokio = { version = "1.2", features = ["full"] }
futures = "0.3"
telegram-bot = "0.8"

citizen-stig avatar Dec 30 '22 15:12 citizen-stig

Root cause

I run cargo tree and see that latest version(0.8) on crates.io is published about 2 years ago and depends on hyper=0.13, which depends on tokio=0.2.25. Here's trimmed output of cargo tree command:

├── anyhow v1.0.68
├── futures v0.3.25
...
├── telegram-bot v0.8.0
│   ├── bytes v0.5.6
│   ├── futures v0.3.25 (*)
│   ├── hyper v0.13.10
│   │   ├── bytes v0.5.6
│   │   ├── futures-channel v0.3.25 (*)
│   │   ├── futures-core v0.3.25
│   │   ├── futures-util v0.3.25 (*)
│   │   ├── h2 v0.2.7
│   │   │   ├── bytes v0.5.6
...
│   │   │   ├── tokio v0.2.25
...
│   │   ├── tokio v0.2.25 (*)
│   │   ├── tower-service v0.3.2
│   │   ├── tracing v0.1.37 (*)
│   │   └── want v0.3.0
│   │       ├── log v0.4.17 (*)
│   │       └── try-lock v0.2.3
│   ├── hyper-tls v0.4.3
...
│   │   ├── tokio v0.2.25 (*)
│   │   └── tokio-tls v0.3.1
│   │       ├── native-tls v0.2.11 (*)
│   │       └── tokio v0.2.25 (*)
...
│   │       └── serde v1.0.152 (*)
│   ├── tokio v0.2.25 (*)
│   ├── tracing v0.1.37 (*)
│   └── tracing-futures v0.2.5 (*)
└── tokio v1.23.0

Potential solutions for this problem

  1. Publish new version on crates.io, something like 0.8.1. This require some effort from maintainers
  2. Workaround to point to dependency from git, like that:
telegram-bot =  { git = "https://github.com/telegram-rs/telegram-bot.git", rev = "65ad5cf" }

I can confirm that second option worked for me. I hope @robertpauson or @gugahoa can publish new version.

citizen-stig avatar Dec 30 '22 16:12 citizen-stig

Same issue for me Using this toml

[dependencies]
telegram-bot = "0.8.0"
tokio = { version = "1.26.0", features = ["fs", "rt", "macros", "rt-multi-thread"]}
futures = { version = "0.3.26", default-features = false }
dotenv = "0.15.0"

Dmdv avatar Mar 21 '23 20:03 Dmdv