Skip to content

Commit 1300292

Browse files
author
Paul C
committed
wolfdisk v2.9.1: clear AddrInUse diagnostic on peer-manager bind
klasSponsor hit 'Failed to start peer manager: Address in use (os error 98)' with no indication of which port or why. std's TcpListener already sets SO_REUSEADDR, so AddrInUse means another process is actively listening on the peer port — almost always a second wolfdisk instance (you do NOT need one for S3: set [s3] enabled = true on the existing wolfdisk), a stale wolfdisk that didn't stop, or a clash with WolfStack's status-page range 8550-8599. The error now names the address and the likely cause and tells the operator to find the holder with ss -ltnp. Also bind BEFORE flipping the running flag true so a failed bind never leaves the manager flagged running. Diagnostics-only; no behaviour change on the success path.
1 parent 595a094 commit 1300292

3 files changed

Lines changed: 28 additions & 5 deletions

File tree

wolfdisk/Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

wolfdisk/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "wolfdisk"
3-
version = "2.9.0"
3+
version = "2.9.1"
44
edition = "2021"
55
authors = ["Wolf Software Systems Ltd"]
66
description = "Distributed file system with replicated and shared storage modes"

wolfdisk/src/network/peer.rs

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,14 +113,37 @@ impl PeerManager {
113113

114114
/// Start listening for peer connections
115115
pub fn start(&self) -> std::io::Result<()> {
116-
*self.running.write().unwrap() = true;
117-
118116
let bind_addr: SocketAddr = self
119117
.bind_address
120118
.parse()
121119
.map_err(|e| std::io::Error::new(std::io::ErrorKind::InvalidInput, e))?;
122-
let listener = TcpListener::bind(bind_addr)?;
120+
// Bind BEFORE flipping `running` true — if the address is taken we must
121+
// not leave the manager flagged as running. std's TcpListener already
122+
// sets SO_REUSEADDR, so AddrInUse here means another process is actively
123+
// listening on this exact port (a second wolfdisk instance, a stale
124+
// wolfdisk that didn't stop, or a clash with WolfStack's status-page
125+
// range 8550-8599). Name the address and the likely cause so the
126+
// operator can find it with `ss -ltnp` instead of a bare errno 98.
127+
let listener = TcpListener::bind(bind_addr).map_err(|e| {
128+
if e.kind() == std::io::ErrorKind::AddrInUse {
129+
std::io::Error::new(
130+
std::io::ErrorKind::AddrInUse,
131+
format!(
132+
"peer port {bind_addr} is already in use — another wolfdisk \
133+
is likely already listening there (you do NOT need a second \
134+
wolfdisk for S3: set `[s3] enabled = true` on the existing \
135+
one). If you really want a second instance, give it a \
136+
different `bind`/`data_dir`. Find the holder with: \
137+
ss -ltnp 'sport = :{port}'",
138+
port = bind_addr.port()
139+
),
140+
)
141+
} else {
142+
e
143+
}
144+
})?;
123145
listener.set_nonblocking(true)?;
146+
*self.running.write().unwrap() = true;
124147

125148
let handler = Arc::clone(&self.message_handler);
126149
let running = Arc::clone(&self.running);

0 commit comments

Comments
 (0)