Skip to content

Commit beb9bc1

Browse files
authored
Explicitly fail if io_uring can't be setup (#1184)
1 parent 80c25ff commit beb9bc1

File tree

2 files changed

+40
-1
lines changed

2 files changed

+40
-1
lines changed

src/cli/service.rs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -468,6 +468,45 @@ impl Service {
468468
Finalizer,
469469
Arc<crate::components::proxy::SessionPool>,
470470
)> {
471+
// If we're on linux, we're using io-uring, but we're probably running in a container
472+
// and may not be allowed to call io-uring related syscalls due to seccomp
473+
// profiles, so do a quick check here to validate that we can call io_uring_setup
474+
// https://www.man7.org/linux/man-pages/man2/io_uring_setup.2.html
475+
#[cfg(target_os = "linux")]
476+
{
477+
if let Err(err) = io_uring::IoUring::new(2) {
478+
fn in_container() -> bool {
479+
let sched = match std::fs::read_to_string("/proc/1/sched") {
480+
Ok(s) => s,
481+
Err(error) => {
482+
tracing::warn!(
483+
%error,
484+
"unable to read /proc/1/sched to determine if quilkin is in a container"
485+
);
486+
return false;
487+
}
488+
};
489+
let Some(line) = sched.lines().next() else {
490+
tracing::warn!("/proc/1/sched was empty");
491+
return false;
492+
};
493+
let Some(proc) = line.split(' ').next() else {
494+
tracing::warn!("first line of /proc/1/sched was empty");
495+
return false;
496+
};
497+
proc != "init" && proc != "systemd"
498+
}
499+
500+
if err.kind() == std::io::ErrorKind::PermissionDenied && in_container() {
501+
eyre::bail!(
502+
"failed to call `io_uring_setup` due to EPERM ({err}), quilkin seems to be running inside a container meaning this is likely due to the seccomp profile not allowing the syscall"
503+
);
504+
} else {
505+
eyre::bail!("failed to call `io_uring_setup` due to {err}");
506+
}
507+
}
508+
}
509+
471510
let socket = crate::net::raw_socket_with_reuse(self.udp_port)?;
472511
let workers = self.udp_workers.get();
473512
let buffer_pool = Arc::new(crate::collections::BufferPool::new(workers, 2 * 1024));

src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ fn main() {
3636
match <quilkin::Cli as clap::Parser>::parse().drive().await {
3737
Ok(()) => std::process::exit(0),
3838
Err(error) => {
39-
tracing::error!(%error, error_debug=?error, "fatal error");
39+
tracing::error!(?error, "fatal error");
4040

4141
std::process::exit(-1)
4242
}

0 commit comments

Comments
 (0)