当我尝试同时使用actix 3和rusoto 0.46时,我得到以下运行时错误:
thread 'actix-rt:worker:0' panicked at 'there is no reactor running, must be called from the context of a Tokio 1.x runtime', /Users/matt/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.2.0/src/runtime/blocking/pool.rs:85:33小的可复制的:
use actix_web::{get, App, HttpResponse, HttpServer, Responder}; // 3
use rusoto_core::Region; // 0.46
use rusoto_dynamodb::{DynamoDb, DynamoDbClient, ListTablesInput};
use std::default::Default;
#[get("/tables")]
async fn tables(_req_body: String) -> impl Responder {
let client = DynamoDbClient::new(Region::default());
let list_tables_input: ListTablesInput = Default::default();
match client.list_tables(list_tables_input).await {
Ok(_output) => HttpResponse::Ok().finish(),
Err(_error) => HttpResponse::InternalServerError().finish(),
}
}
#[actix_web::main]
async fn main() -> std::io::Result<()> {
HttpServer::new(|| App::new().service(tables))
.bind("0.0.0.0:8080")?
.run()
.await
}随附货物档案:
[package]
name = "hello_actix_rusoto"
version = "0.1.0"
authors = ["Matt Roberts <mattroberts297@users.noreply.github.com>"]
edition = "2018"
[dependencies]
rusoto_core = "0.46"
rusoto_dynamodb = "0.46"
actix-web = "3"下面是一个包含完整代码的链接到一个非常小的GitHub回购,下面是如何再现错误:
git clone git@github.com:mattroberts297/hello_actix_rusoto.git
cd hello_actix_rusoto
docker-compose up -d
AWS_REGION=local cargo run &
curl -v 'http://127.0.0.1:8080/tables'发布于 2021-02-09 14:21:47
rusoto v0.46依赖于tokio v1.0。然而,actix-web v3仍在使用tokio v0.2。这两个版本不向后兼容,因此出现了错误消息。要解决这个问题,您可以升级到actix的更新版本:
actix-web = "4.0.0-beta.8"或者您可以使用tokio-compat2兼容层。这需要在任何不兼容的.await调用前加上.compat()。
async fn index() -> impl Responder {
let client = DynamoDbClient::new("[region]");
let tables = client.list_tables(list_tables_input).compat().await;
// ...
}或者您可以将rusoto降级为使用tokio v0.2的旧版本:
rusoto_core = "0.43"https://stackoverflow.com/questions/66119865
复制相似问题