fix: hanging server (#806)
Since the update to actix-rt@2.3 (f413996a
), the web server hasn't been
started, when we executed `cargo run -p rust-code-analysis-web`.
It froze once `actix_rt::System::new().run()?;` was called,
effectively preventing the execution of the code below.
By looking at the actix-rt examples and changing the code to be more
like the examples, I was able to fix this.
The webserver now behaves as expected.
This commit is contained in:
Родитель
97e576b90a
Коммит
08c61f48ad
|
@ -9,7 +9,8 @@ use clap::{crate_version, App, Arg};
|
|||
|
||||
use web::server;
|
||||
|
||||
fn main() {
|
||||
#[actix_web::main]
|
||||
async fn main() {
|
||||
let matches = App::new("rust-code-analysis-web")
|
||||
.version(crate_version!())
|
||||
.author(&*env!("CARGO_PKG_AUTHORS").replace(':', "\n"))
|
||||
|
@ -51,7 +52,7 @@ fn main() {
|
|||
eprintln!("Invalid port number");
|
||||
return;
|
||||
};
|
||||
if let Err(e) = server::run(host.to_string(), port, num_jobs) {
|
||||
if let Err(e) = server::run(host.to_string(), port, num_jobs).await {
|
||||
eprintln!("Cannot run the server at {}:{}: {}", host, port, e);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
use actix_rt::Runtime;
|
||||
use actix_web::{
|
||||
dev::Body,
|
||||
guard, http,
|
||||
|
@ -220,12 +219,9 @@ fn ping() -> HttpResponse {
|
|||
HttpResponse::Ok().body(Body::Empty)
|
||||
}
|
||||
|
||||
pub fn run(host: String, port: u16, n_threads: usize) -> std::io::Result<()> {
|
||||
actix_rt::System::new().run()?;
|
||||
let rt = Runtime::new()?;
|
||||
pub async fn run(host: String, port: u16, n_threads: usize) -> std::io::Result<()> {
|
||||
let max_size = 1024 * 1024 * 4;
|
||||
|
||||
rt.block_on(async move {
|
||||
HttpServer::new(move || {
|
||||
App::new()
|
||||
.service(
|
||||
|
@ -284,7 +280,6 @@ pub fn run(host: String, port: u16, n_threads: usize) -> std::io::Result<()> {
|
|||
.bind((host.as_str(), port))?
|
||||
.run()
|
||||
.await
|
||||
})
|
||||
}
|
||||
|
||||
// curl --header "Content-Type: application/json" --request POST --data '{"id": "1234", "file_name": "prova.cpp", "code": "int x = 1;", "comment": true, "span": true}' http://127.0.0.1:8081/ast
|
||||
|
|
Загрузка…
Ссылка в новой задаче