From 6b3ac2a44b1674f156bc369d7e9f2913f10c258c Mon Sep 17 00:00:00 2001 From: Quinn Smith Date: Sat, 8 Feb 2025 15:12:53 -0800 Subject: [PATCH] Improve host ports exhausted panic message I've added the hostname to the error message. While debugging an issue I found this useful. I want to put this back so others can benefit from this too. --- src/host.rs | 8 +++++++- src/world.rs | 1 + 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/host.rs b/src/host.rs index 2e2b8a3..daba0c8 100644 --- a/src/host.rs +++ b/src/host.rs @@ -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, @@ -37,6 +40,7 @@ pub(crate) struct Host { impl Host { pub(crate) fn new( + nodename: impl Into, addr: IpAddr, timer: HostTimer, ephemeral_ports: RangeInclusive, @@ -44,6 +48,7 @@ impl Host { udp_capacity: usize, ) -> Host { Host { + nodename: nodename.into(), addr, udp: Udp::new(udp_capacity), tcp: Tcp::new(tcp_capacity), @@ -73,7 +78,7 @@ impl Host { return ret; } - panic!("Host ports exhausted") + panic!("Host: '{}' ports exhausted", self.nodename) } /// Receive the `envelope` from the network. @@ -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, diff --git a/src/world.rs b/src/world.rs index 7748006..9765528 100644 --- a/src/world.rs +++ b/src/world.rs @@ -229,6 +229,7 @@ impl World { self.hosts.insert( addr, Host::new( + nodename, addr, timer, config.ephemeral_ports.clone(),