UdpSocket not closed after task return

Is it supposed to drop socket after the task return

async fn main() {
   run_udp_server().await; // after return, socket is still using

async fn run_udp_server() {
    let udp_socket = UdpSocket::bind("")).await.unwrap();
    let udp_socket_clone = udp_socket.clone();
    tokio::spawn(async {
       loop {

You seem to spawn a task (with tokio::spawn) that keeps using the socket in an infinite loop. Isn’t that why it’s kept open?

Also, I’m not sure what exactly your code is doing. Your line

let udp_socket = UdpSocket::bind("")).await.unwrap();

has a parenthesis to much, and if this is tokio’s UdpSocket, that type isn’t even cloneable...

1 Like

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.