I am unable to compile the following on Linux (Ubuntu 18 Bionic Beaver). I have tried both Docker and VirtualBox VMs, but rustc
eventually runs out of memory on both. The code compiles without issue on macOS, and compiled on Linux until roughly 5 days ago.
use {
actix_web::{
get,
web::{self},
App, HttpResponse, HttpServer,
},
mongodb::{
options::{ClientOptions, StreamAddress},
Client, Database,
},
};
#[actix_rt::main]
async fn main() -> std::io::Result<()> {
let options = ClientOptions::builder()
.hosts(vec![StreamAddress {
hostname: "localhost".into(),
port: Some(27017),
}])
.build();
let client = Client::with_options(options).unwrap();
HttpServer::new(move || {
App::new()
.data(AppState {
db: client.database("mydb"),
})
.service(hi)
})
.bind("localhost:3000")
.unwrap()
.run()
.await;
Ok(())
}
#[get("/hi")]
async fn hi(state: web::Data<AppState>) -> actix_web::Result<HttpResponse> {
state.db.collection("mycoll").find(None, None).await;
HttpResponse::Ok().await
}
struct AppState {
db: Database,
}
Dependencies in Cargo.toml:
[dependencies]
actix-rt = "1.1.1"
actix-web = "2.0.0"
mongodb = "1.1.0"
The only thing that changed between the last CI build that succeeded and the first one that started failing was adding an endpoint to the server (which was essentially a copy/paste of an existing one), and a minor version bump on the time crate (indirect dependency). Checking out the last working commit and attempting to build that doesn't work.
If I remove the await
on the find()
call it will compile on Linux, but it will also compile if I put that find
call (with the await
) in a non-Actix async fn
.
It also works if I use the sync
feature of mongo, which wouldn't be ideal.
Downgrading to Rust 1.45 allows it to compile, so apparently something in the 1.46 release broke the actix or mongo crates in some way.
Because this code works on macOS, and worked on Linux last week, I'm assuming there is not a fundamental issue with using Mongo in an Actix-web route handler like this. Am I missing something?