Skip to content

Commit 54352b8

Browse files
committed
fix: Improve broadcast error logging
1 parent 30dfd6a commit 54352b8

File tree

1 file changed

+19
-6
lines changed

1 file changed

+19
-6
lines changed

shared/src/conn/outgoing.rs

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,11 @@ impl Pool {
185185
Ok(())
186186
}
187187

188+
/// Broadcasts a BeeMsg datagram to all given nodes using all their known addresses
189+
///
190+
/// Logs errors if sending failed completely for a node, only fails if serialization fails.
191+
/// Remember that this is UDP and thus no errors only means that the sending was successful,
192+
/// not that the messages reached their destinations.
188193
pub async fn broadcast_datagram<M: Msg + Serializable>(
189194
&self,
190195
peers: impl IntoIterator<Item = Uid>,
@@ -196,18 +201,26 @@ impl Pool {
196201
for node_uid in peers {
197202
let addrs = self.store.get_node_addrs(node_uid).unwrap_or_default();
198203

199-
let mut sent = false;
204+
if addrs.is_empty() {
205+
log::error!(
206+
"Failed to send datagram to node with uid {node_uid}: No known addresses"
207+
);
208+
continue;
209+
}
210+
211+
let mut errs = vec![];
200212
for addr in addrs.iter() {
201213
if let Err(err) = buf.send_to_socket(&self.udp_socket, addr).await {
202-
log::debug!("Sending datagram to {addr} failed: {err}");
203-
continue;
214+
log::debug!(
215+
"Sending datagram to node with uid {node_uid} using {addr} failed: {err}"
216+
);
217+
errs.push((addr, err));
204218
}
205-
sent = true;
206219
}
207220

208-
if !sent {
221+
if errs.len() == addrs.len() {
209222
log::error!(
210-
"Failed to send datagram to node with uid {node_uid}: Sending failed for all known addresses"
223+
"Failed to send datagram to node with uid {node_uid} on all known addresses: {errs:?}"
211224
);
212225
}
213226
}

0 commit comments

Comments
 (0)