webrtc
webrtc copied to clipboard
TURN client wont close the socket
In my application, I've observed that when a TURN server is used as a proxy, numerous UDP sockets remain open even after all network activities have ceased and there are no clients connected. I've pinpointed the issue to this section of code: https://github.com/webrtc-rs/webrtc/blob/master/turn/src/client/mod.rs#L235-L241. The problem appears to stem from the recv_from method, which lacks a timeout mechanism.
To address this issue, I'm considering implementing a timeout for the recv_from call to ensure it doesn't hang indefinitely. Here's a proposed solution:
let (n, from) = match tokio::time::timeout(timeout_duration, conn.recv_from(&mut buf)).await {
Ok(Ok((n, from))) => (n, from), // Successfully received data within the set timeout
Ok(Err(err)) => {
log::debug!("Encountered a network error: {}", err);
break;
}
Err(_) => {
log::debug!("The recv_from call timed out after {:?}", timeout_duration);
break; // Terminating the loop if a timeout is encountered
}
};
which works for me, not sure if that'd work for you. Any thoughts on that?
@rainliu what are your thoughts on the above? Would you like a PR for this?