tokio-rs / tokio-uring

An io_uring backed runtime for Rust
MIT License
1.11k stars 117 forks source link

Panic when calling recv_from() after shutdown() #303

Open zinid opened 3 months ago

zinid commented 3 months ago

Environment

Description

A panic occurs when calling recv_from() on a UdpSocket after the socket has been shut down using shutdown(). The error message indicates that an Option::unwrap() is called on a None value within the recv_from method of the tokio-uring library.

Steps to Reproduce

  1. Compile and run the following Rust code using Tokio-Uring:

    use std::net::{Shutdown, SocketAddr};
    use tokio_uring::net::UdpSocket;
    
    fn main() -> Result<(), std::io::Error> {
        tokio_uring::start(async {
            let local_addr: SocketAddr = "0.0.0.0:0".parse().unwrap();
            let socket = UdpSocket::bind(local_addr).await?;
            let buf = vec![0; 8196];
            let _ = socket.shutdown(Shutdown::Both);
            let _ = socket.recv_from(buf).await;
    
            Ok(())
        })
    }
  2. Run the program with cargo run.

Expected Behavior

The program should handle the shutdown state gracefully, either by returning a specific error or by not panicking.

Observed Behavior

The program panics with the following message:

thread 'main' panicked at ~/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-uring-0.5.0/src/io/recv_from.rs:71:55: called `Option::unwrap()` on a `None` value