diff --git a/src/commands.rs b/src/commands.rs index 0791890ef..6620d2e7d 100644 --- a/src/commands.rs +++ b/src/commands.rs @@ -282,6 +282,9 @@ fn connect_or_start_server(port: u16) -> Result { ); } } + ServerStartup::AddrInUse => { + debug!("AddrInUse: possible parallel server bootstraps, retrying..") + } ServerStartup::TimedOut => bail!("Timed out waiting for server startup"), ServerStartup::Err { reason } => bail!("Server startup failed: {}", reason), } @@ -587,6 +590,7 @@ pub fn run_command(cmd: Command) -> Result { } } ServerStartup::TimedOut => bail!("Timed out waiting for server startup"), + ServerStartup::AddrInUse => bail!("Server startup failed: Address in use"), ServerStartup::Err { reason } => bail!("Server startup failed: {}", reason), } } diff --git a/src/server.rs b/src/server.rs index 30c5660bc..39a5f1663 100644 --- a/src/server.rs +++ b/src/server.rs @@ -79,6 +79,8 @@ const DIST_CLIENT_RECREATE_TIMEOUT: Duration = Duration::from_secs(30); pub enum ServerStartup { /// Server started successfully on `port`. Ok { port: u16 }, + /// Server Addr already in suse + AddrInUse, /// Timed out waiting for server startup. TimedOut, /// Server encountered an error. @@ -412,8 +414,15 @@ pub fn start_server(config: &Config, port: u16) -> Result<()> { } Err(e) => { error!("failed to start server: {}", e); - let reason = e.to_string(); - notify_server_startup(¬ify, ServerStartup::Err { reason })?; + match e.downcast_ref::() { + Some(io_err) if io::ErrorKind::AddrInUse == io_err.kind() => { + notify_server_startup(¬ify, ServerStartup::AddrInUse)?; + } + _ => { + let reason = e.to_string(); + notify_server_startup(¬ify, ServerStartup::Err { reason })?; + } + }; Err(e) } }