async-net icon indicating copy to clipboard operation
async-net copied to clipboard

`UdpSocket::peek_from` is returning weird error on IPv6 on MacOS

Open al8n opened this issue 9 months ago • 0 comments
trafficstars

Hi, I found that UdpSocket::peek_from returns a weird error when using the IPv6 address on MacOS (I also tested on Linux, Linux works, windows not sure).

Here is the test case that can reproduce the error situation, If you change the address to IPv4, then everything is fine.

macro_rules! t {
  ($e:expr) => {
    match $e {
      Ok(t) => t,
      Err(e) => panic!("received error for `{}`: {}", stringify!($e), e),
    }
  };
}

#[test]
fn test_peek_from_ipv6() {
  ::smol::block_on(async move {
    let addr: std::net::SocketAddr = "[::1]:8080".parse().unwrap();
    let socket = t!(::smol::net::UdpSocket::bind(&addr).await);
      t!(socket.send_to(b"hello world", &addr).await);

  
      for _ in 1..3 {
        let mut buf = [0; 11];
        let (size, _) = t!(socket.peek_from(&mut buf).await);
        assert_eq!(b"hello world", &buf[..]);
        assert_eq!(size, 11);
      }

  
      let mut buf = [0; 11];
      let (size, _) = t!(socket.recv_from(&mut buf).await);
      assert_eq!(b"hello world", &buf[..]);
      assert_eq!(size, 11);
  });
}

The panic output is:

received error for `socket.peek_from(&mut buf).await`: Resource temporarily unavailable (os error 35)

Edit:

IPv4 addr also gives the same error randomly.

al8n avatar Jan 24 '25 15:01 al8n