Skip to content

Commit

Permalink
Improve host ports exhausted panic message (#218)
Browse files Browse the repository at this point in the history
I've added the hostname to the error message. While debugging an issue I
found this useful.
  • Loading branch information
quinnwerks authored Feb 14, 2025
1 parent 2704e8e commit 65765f3
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/host.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ use tokio::time::{Duration, Instant};
///
/// Both modes may be used simultaneously.
pub(crate) struct Host {
/// Host name.
pub(crate) nodename: String,

/// Host ip address.
pub(crate) addr: IpAddr,

Expand All @@ -37,13 +40,15 @@ pub(crate) struct Host {

impl Host {
pub(crate) fn new(
nodename: impl Into<String>,
addr: IpAddr,
timer: HostTimer,
ephemeral_ports: RangeInclusive<u16>,
tcp_capacity: usize,
udp_capacity: usize,
) -> Host {
Host {
nodename: nodename.into(),
addr,
udp: Udp::new(udp_capacity),
tcp: Tcp::new(tcp_capacity),
Expand Down Expand Up @@ -73,7 +78,7 @@ impl Host {
return ret;
}

panic!("Host ports exhausted")
panic!("Host: '{}' ports exhausted", self.nodename)
}

/// Receive the `envelope` from the network.
Expand Down Expand Up @@ -462,6 +467,7 @@ mod test {
#[test]
fn recycle_ports() -> Result {
let mut host = Host::new(
"host",
std::net::Ipv4Addr::UNSPECIFIED.into(),
HostTimer::new(Duration::ZERO),
49152..=49162,
Expand Down
1 change: 1 addition & 0 deletions src/world.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@ impl World {
self.hosts.insert(
addr,
Host::new(
nodename,
addr,
timer,
config.ephemeral_ports.clone(),
Expand Down

0 comments on commit 65765f3

Please sign in to comment.