Skip to content

Commit 06f7809

Browse files
authored
Fix deserialization abort and not logging datagram handling errors (ThinkParQ/beegfs-rs#183)
2 parents 102d604 + 846162c commit 06f7809

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

shared/src/bee_serde.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,9 @@ impl<'a> Deserializer<'a> {
338338

339339
let len = self.u32()? as usize;
340340

341-
let mut v = Vec::with_capacity(len);
341+
let mut v = Vec::new();
342+
v.try_reserve_exact(len)?;
343+
342344
for _ in 0..len {
343345
v.push(f(self)?);
344346
}
@@ -371,7 +373,9 @@ impl<'a> Deserializer<'a> {
371373

372374
let len = self.u32()? as usize;
373375

374-
let mut v = HashMap::with_capacity(len);
376+
let mut v = HashMap::new();
377+
v.try_reserve(len)?;
378+
375379
for _ in 0..len {
376380
v.insert(f_key(self)?, f_value(self)?);
377381
}

shared/src/conn/incoming.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,10 @@ async fn stream_loop(
118118
}
119119
}
120120

121-
log::error!("Closed stream from {:?}: {err:#}", stream.addr());
121+
log::error!(
122+
"Error while handling stream from {:?}: {err:#}",
123+
stream.addr()
124+
);
122125
return;
123126
}
124127
}
@@ -143,8 +146,8 @@ async fn read_stream(
143146
&& buf.msg_id() != AuthenticateChannel::ID
144147
{
145148
bail!(
146-
"Received message on unauthenticated stream from {:?}",
147-
stream.addr()
149+
"Stream is not authenticated and received message with id {}",
150+
buf.msg_id()
148151
);
149152
}
150153

@@ -220,7 +223,9 @@ async fn recv_datagram(sock: Arc<UdpSocket>, msg_handler: impl DispatchRequest)
220223
};
221224

222225
// Forward to the dispatcher
223-
let _ = msg_handler.dispatch_request(req).await;
226+
if let Err(err) = msg_handler.dispatch_request(req).await {
227+
log::error!("Error while handling datagram from {peer_addr:?}: {err:#}");
228+
}
224229
});
225230

226231
Ok(())

0 commit comments

Comments
 (0)