Skip to content

Commit

Permalink
[validator] Wrap AddrInUse errors so we can see what address could no…
Browse files Browse the repository at this point in the history
…t be bound (MystenLabs#1657)
  • Loading branch information
velvia authored Apr 29, 2022
1 parent 4688772 commit e50b4eb
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
10 changes: 9 additions & 1 deletion network_utils/src/transport.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,15 @@ where
S: MessageHandler<TcpDataStream> + Send + Sync + 'static,
{
let (tx_cancellation, rx_cancellation) = futures::channel::oneshot::channel();
let std_listener = std::net::TcpListener::bind(address)?;
info!(address =% address, "Attempting to spawn server and bind to address...");
let std_listener = std::net::TcpListener::bind(address).map_err(|e| match e.kind() {
// Wrap custom error to give information about the address that could not be bbound
ErrorKind::AddrInUse => std::io::Error::new(
ErrorKind::AddrInUse,
format!("Address {address} was in use!"),
),
_ => e,
})?;

let local_addr = std_listener.local_addr()?;
let host = local_addr.ip();
Expand Down
4 changes: 2 additions & 2 deletions sui/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,10 @@ pub struct AuthorityPrivateInfo {
fn socket_addr_from_hostport(host: &str, port: u16) -> SocketAddr {
let mut addresses = format!("{host}:{port}")
.to_socket_addrs()
.expect("Cannot parse {host} and {port} into socket address");
.unwrap_or_else(|e| panic!("Cannot parse or resolve hostnames for {host}:{port}: {e}"));
addresses
.next()
.expect("Hostname/IP resolution failed for {host}")
.unwrap_or_else(|| panic!("Hostname/IP resolution failed for {host}"))
}

// Custom deserializer with optional default fields
Expand Down

0 comments on commit e50b4eb

Please sign in to comment.