io-uring: LinkTimeout randomly ignored
I have noticed in my program, that when adding a LinkTimeout operation after a Connect, sometimes (randomly) the timeout is ignored and the connect operation blocks forever.
It seems to occur more frequently when the binary is compiled in release mode.
I have made a minimal program, which allows me to reproduce 100% of the time (run with cargo run --release), the program should not block more that 3 seconds, but it does:
Cargo.toml:
[package]
name = "io_uring_test"
version = "0.1.0"
edition = "2021"
[dependencies]
io-uring = "0.5.9"
nix = { version = "0.25.0", default-features = false, features = ["net", "socket"] }
src/main.rs:
use io_uring::{
opcode, squeue,
types::{Fd, Timespec},
IoUring,
};
use nix::sys::socket::{socket, AddressFamily, SockFlag, SockType, SockaddrIn, SockaddrLike};
fn main() {
let mut ring = IoUring::new(8).unwrap();
let sckt = socket(
AddressFamily::Inet,
SockType::Stream,
SockFlag::empty(),
None,
)
.unwrap();
let addr = SockaddrIn::new(37, 187, 0, 1, 80); // an IP that does not respond
let op_connect = opcode::Connect::new(Fd(sckt), addr.as_ptr(), addr.len())
.build()
.flags(squeue::Flags::IO_LINK)
.user_data(1);
let op_connect_timeout = opcode::LinkTimeout::new(&Timespec::new().sec(3))
.build()
.user_data(2);
let ops = [op_connect, op_connect_timeout];
eprintln!("{ops:?}");
for op in &ops {
unsafe {
ring.submission().push(op).unwrap();
}
}
ring.submit_and_wait(2).unwrap();
}
EDIT: removed use of unsafe feature flag.
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 22 (11 by maintainers)
Commits related to this issue
- fix: timeouts See https://github.com/tokio-rs/io-uring/issues/156#issuecomment-1309745592 — committed to synacktiv/io_uring_scanner by desbma-s1n 2 years ago
BTW, the reproducer from above works on my Linux machine - debug mode. Times out after the desired number of seconds. I’m on
Linux nuc 5.15.0-48-generic #54-Ubuntu SMP Fri Aug 26 13:26:29 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux
But it also fails to timeout when it should with a release build. That’s interesting. Also finally timing out after 2m10s.