Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TURN client wont close the socket #510

Open
magniff opened this issue Nov 7, 2023 · 1 comment
Open

TURN client wont close the socket #510

magniff opened this issue Nov 7, 2023 · 1 comment

Comments

@magniff
Copy link

magniff commented Nov 7, 2023

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?

@kenaniah
Copy link

kenaniah commented Nov 8, 2023

@rainliu what are your thoughts on the above? Would you like a PR for this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants