Skip to content

Commit

Permalink
Better error message for port already in use
Browse files Browse the repository at this point in the history
  • Loading branch information
xnorpx committed Nov 18, 2024
1 parent d29d0d3 commit 5240bc7
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use std::{
};
use tokio::sync::Mutex;
use tokio_util::sync::CancellationToken;
use tracing::{debug, info, Level};
use tracing::{debug, error, info, Level};
use uuid::Uuid;

const MEGABYTE: usize = 1024 * 1024; // 1 MB = 1024 * 1024 bytes
Expand Down Expand Up @@ -59,7 +59,15 @@ pub async fn run_server(

let addr = SocketAddr::new(Ipv4Addr::UNSPECIFIED.into(), port);
info!("Starting server, listening on {}", addr);
let listener = tokio::net::TcpListener::bind(addr).await?;
let listener = match tokio::net::TcpListener::bind(addr).await {
Ok(listener) => listener,
Err(e) if e.kind() == std::io::ErrorKind::AddrInUse => {
error!("Looks like {port} is already in use either by Blue candle, CPAI or another application, please turn off the other application or pick another port with --port");
return Err(e.into());
}
Err(e) => return Err(e.into()),
};

axum::serve(listener, blue_candle.into_make_service())
.with_graceful_shutdown(async move {
cancellation_token.cancelled().await;
Expand Down

0 comments on commit 5240bc7

Please sign in to comment.