-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Open
Labels
A-tokioArea: The main tokio crateArea: The main tokio crateC-bugCategory: This is a bug.Category: This is a bug.M-netModule: tokio/netModule: tokio/net
Description
Version
tokio v1.41.1 (but master is affected too)
Platform
Linux meeting-data 6.8.0-1029-aws #31~22.04.1-Ubuntu SMP Thu Apr 24 21:16:18 UTC 2025 x86_64 GNU/Linux
Description
The issue is TcpStream::connect may sometimes return EADDRNOTAVAIL (errno 99) hiding the actual error that occurred in an ipv4 connection.
When running in an ipv4-only environment (i.e. no external ipv6), getaddrinfo will happily return ipv6 addresses as well. The problem is that the code
tokio/tokio/src/net/tcp/stream.rs
Lines 116 to 132 in 5efb1c3
| let addrs = to_socket_addrs(addr).await?; | |
| let mut last_err = None; | |
| for addr in addrs { | |
| match TcpStream::connect_addr(addr).await { | |
| Ok(stream) => return Ok(stream), | |
| Err(e) => last_err = Some(e), | |
| } | |
| } | |
| Err(last_err.unwrap_or_else(|| { | |
| io::Error::new( | |
| io::ErrorKind::InvalidInput, | |
| "could not resolve to any address", | |
| ) | |
| })) |
getaddrinforeturns [IPV4, IPv6] in that order- Attempt to connect to IPV4 yields an actual network error (e.g. timeout, connection refused)
- The code attempts an IPV6 connection.
- The IPV6 connection fails with
EADDRNOTAVAILsince the host doesn't have external IPv6 support enabled. - The last error wins, so instead of a "connection refused" message, you get a "cannot assign requested address"
For reference for others, one fix for this is to disable returning ipv6 addresses - add options no-aaaa to /etc/resolv.conf.
anmonteiroanmonteiroanmonteiro
Metadata
Metadata
Assignees
Labels
A-tokioArea: The main tokio crateArea: The main tokio crateC-bugCategory: This is a bug.Category: This is a bug.M-netModule: tokio/netModule: tokio/net