[RustShell] thread 'main' panicked at 'there is no reactor running, must be called from the context of a Tokio 1.x runtime'
Project

[RustShell] thread 'main' panicked at 'there is no reactor running, must be called from the context of a Tokio 1.x runtime'

반응형

What happened?

Rust를 이용한 Shell 만들기 프로젝트를 진행하고 있었다. p2p를 사용한 built-in 채팅 명령어를 시험 삼아 만들고 돌리려는데 다음과 같은 에러가 떴다.

thread 'main' panicked at 'there is no reactor running, must be called from the context of a Tokio 1.x runtime', /home/karatus/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.17.0/src/runtime/context.rs:29:26

tokio 크레이트의 1.x 버전 런타임 컨텍스트로 부르지 않아 생긴 일이다.

 

How to solve?

1) Did you check your main (or something else) is using 'async' keyword now?

나 같은 경우는 정말 간단했다. 단순히 tokio의 비동기 함수를 사용하기 위한 설정을 안 해줬던 것이다...

그래서 main에 #[tokio::main]을 추가하여 비동기화시켜주었다.

2) Dependencies are confusing everything

당연히 구글링을 통해 처음에 알아보았는데 대부분이 나와 같은 실수로 인해 생긴 것이 아니라 의존성 문제였다. tokio를 사용하는 디펜던시들이 서로 다른 tokio 버전을 원하는 경우가 있어 발생하는 에러였다.

tokio는 현재 크게 두 가지 버전으로 나눌 수 있는데, 하나는 0.3 버전이고 다른 하나는 현재의 1.x 버전이다. 이렇다 보니 오래된 crate에서 사용하는 tokio가 이 두 가지 버전이 아닌 0.2.x와 같은 지원하지 않는 버전을 사용하는 경우 위와 같은 에러가 발생했던 것이다.

https://stackoverflow.com/questions/64779920/why-do-i-get-the-error-there-is-no-reactor-running-must-be-called-from-the-con

 

Why do I get the error "there is no reactor running, must be called from the context of Tokio runtime" even though I have #[toki

I'm following the mdns Rust documentation and pasted the example code but it throws the following error: thread 'main' panicked at 'there is no reactor running, must be called from the context of T...

stackoverflow.com

그러니 앞으로 디펜던시 문제가 발생할 때는 crates.io에서 해당 crate의 Dependencies 부분을 참고하면 좋을 것이다. 예를 들어 다음과 같이 말이다.

https://crates.io/crates/libp2p/0.43.0/dependencies

반응형