Skip to content

Commit

Permalink
New entry in ServerStartup enum to indicate AddrInUse Error (#840)
Browse files Browse the repository at this point in the history
when cargo fires of parallel build jobs, we encounter a race to start
the server if the server is not already running to start the server

This is an AddrInUse error causing atleast one of the parallel build
jobs fail.

This patch adds a new entry to ServerStartup enum to clearly communicate
the AddrInUse error from the server to the client that requested the
server start. Using this information the client can retry connecting
instead of failing.
  • Loading branch information
sum12 authored Sep 28, 2020
1 parent ea4d146 commit 6628e1f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
4 changes: 4 additions & 0 deletions src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,9 @@ fn connect_or_start_server(port: u16) -> Result<ServerConnection> {
);
}
}
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),
}
Expand Down Expand Up @@ -587,6 +590,7 @@ pub fn run_command(cmd: Command) -> Result<i32> {
}
}
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),
}
}
Expand Down
13 changes: 11 additions & 2 deletions src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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(&notify, ServerStartup::Err { reason })?;
match e.downcast_ref::<io::Error>() {
Some(io_err) if io::ErrorKind::AddrInUse == io_err.kind() => {
notify_server_startup(&notify, ServerStartup::AddrInUse)?;
}
_ => {
let reason = e.to_string();
notify_server_startup(&notify, ServerStartup::Err { reason })?;
}
};
Err(e)
}
}
Expand Down

0 comments on commit 6628e1f

Please sign in to comment.