Skip to content

Commit 13d1f66

Browse files
committed
fix: don't break udp socket when receiving an invalid message, improve logging
Found by test_empty_udp_packets_server integration test. The test needs to be changed as well to adapt to the corrected log output (it was not really correct before)
1 parent e78e1c0 commit 13d1f66

File tree

1 file changed

+17
-12
lines changed

1 file changed

+17
-12
lines changed

shared/src/conn/incoming.rs

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -199,8 +199,7 @@ pub fn recv_udp(
199199
// Do the actual work
200200
res = recv_datagram(sock.clone(), dispatch.clone()) => {
201201
if let Err(err) = res {
202-
log::error!("Error in UDP socket {sock:?}: {err:#}");
203-
break;
202+
log::error!("Error on receiving datagram using UDP socket {:?}: {err:#}", sock.local_addr());
204203
}
205204
}
206205

@@ -227,20 +226,26 @@ async fn recv_datagram(sock: Arc<UdpSocket>, msg_handler: impl DispatchRequest)
227226

228227
let (_, peer_addr) = sock.recv_from(&mut buf).await?;
229228

230-
let header = deserialize_header(&buf[0..Header::LEN])?;
231-
232229
// Request shall be handled in a separate task, so the next datagram can be processed
233230
// immediately
234231
tokio::spawn(async move {
235-
let req = SocketRequest {
236-
sock,
237-
peer_addr,
238-
buf: &mut buf,
239-
header: &header,
240-
};
232+
if let Err(err) = async {
233+
let header = deserialize_header(&buf[0..Header::LEN])?;
234+
235+
let req = SocketRequest {
236+
sock,
237+
peer_addr,
238+
buf: &mut buf,
239+
header: &header,
240+
};
241241

242-
// Forward to the dispatcher
243-
if let Err(err) = msg_handler.dispatch_request(req).await {
242+
// Forward to the dispatcher
243+
msg_handler.dispatch_request(req).await?;
244+
245+
Ok::<(), anyhow::Error>(())
246+
}
247+
.await
248+
{
244249
log::error!("Error while handling datagram from {peer_addr:?}: {err:#}");
245250
}
246251
});

0 commit comments

Comments
 (0)