Skip to content

Commit

Permalink
feat: [#609] add timeout to UDP tracker requests
Browse files Browse the repository at this point in the history
  • Loading branch information
josecelano committed Jan 16, 2024
1 parent b001ffd commit fec9716
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/servers/udp/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
use std::io::Cursor;
use std::net::SocketAddr;
use std::sync::Arc;
use std::time::Duration;

use aquatic_udp_protocol::Response;
use derive_more::Constructor;
Expand Down Expand Up @@ -240,9 +241,16 @@ impl Udp {
debug!(target: "UDP Tracker", "From: {}", &remote_addr);
debug!(target: "UDP Tracker", "Payload: {:?}", payload);

let response = handle_packet(remote_addr, payload, &tracker).await;
let response_fut = handle_packet(remote_addr, payload, &tracker);

Check warning on line 244 in src/servers/udp/server.rs

View check run for this annotation

Codecov / codecov/patch

src/servers/udp/server.rs#L244

Added line #L244 was not covered by tests

Udp::send_response(socket_clone, remote_addr, response).await;
match tokio::time::timeout(Duration::from_secs(5), response_fut).await {
Ok(response) => {
Udp::send_response(socket_clone, remote_addr, response).await;
}
Err(_) => {
error!("Timeout occurred while processing the UDP request.");

Check warning on line 251 in src/servers/udp/server.rs

View check run for this annotation

Codecov / codecov/patch

src/servers/udp/server.rs#L246-L251

Added lines #L246 - L251 were not covered by tests
}
}
}
Err(err) => {
error!("Error reading UDP datagram from socket. Error: {:?}", err);
Expand Down

0 comments on commit fec9716

Please sign in to comment.