Skip to content

fix(io): prevent io_uring requests from hanging - #8725

Merged
Xuanwo merged 2 commits into
mainfrom
xuanwo/fix-io-uring-hang
Aug 24, 2026
Merged

Xuanwo merged 2 commits into
mainfrom
xuanwo/fix-io-uring-hang

Conversation

@Xuanwo

@Xuanwo Xuanwo commented Aug 24, 2026

Copy link
Copy Markdown
Member

Fixes #8723.

The io_uring request sender was published before ring initialization. If initialization failed, a request could be accepted by a channel whose worker had already exited, leaving its future pending indefinitely.

This change:

  • initializes rings before publishing workers and returns the initialization errors when no worker is available;
  • detects worker death around request submission and fails pending and queued requests after hard submission errors;
  • drains every queued SQE across interrupted or partial submissions; and
  • adds regression coverage for initialization failure and submission progress.

Validation:

  • cargo test -p lance-io uring:: -- --test-threads=1 on Linux: 18 passed;
  • cargo clippy --all --tests --benches -- -D warnings;
  • an unprivileged Linux environment reproduced the pre-fix indefinite wait when io_uring_setup returned EPERM; the fixed path returns the preserved initialization error immediately.

CI and nextest configuration are unchanged.

@github-actions github-actions Bot added A-encoding Encoding, IO, file reader/writer bug Something isn't working labels Aug 24, 2026
@Xuanwo
Xuanwo marked this pull request as ready for review August 24, 2026 15:58

@lance-gatekeeper lance-gatekeeper Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❌ Gate recommendation: request changes.

The startup and submission-progress fixes are directionally sound, but fatal-worker shutdown must make admission and draining atomic. Every successful enqueue must either be failed by its sender or remain visible to the worker's final drain; otherwise the indefinite-pending state remains reachable.

A viable revision can serialize admission with shutdown or use a channel/ownership protocol whose close operation prevents successful late enqueue, with a deterministic concurrent-send regression.

for request in pending.drain().map(|(_, request)| request) {
request.fail(io::Error::new(error_kind, error_message.clone()));
}
for request in request_rx.try_iter() {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A successful send can land after this one-shot drain. A sender that read is_alive == true may enqueue while the receiver is still open after try_iter() has observed empty; because the failed receive does not synchronize the worker's Release store with that later sender, its post-send Acquire load can still observe true. The receiver then drops the queued Arc<IoRequest>, leaving the future's copy incomplete and never woken.

Make closing admission atomic with the final drain—for example, serialize the liveness check plus send against mark-dead plus drain, or use a closeable ownership protocol where a successful send is guaranteed to be drainable. Add a bounded concurrency regression.

Bounded reproducer

With loom = "0.7.2", I ran cargo run --offline on this model of the current protocol:

use loom::sync::{
    Arc,
    atomic::{AtomicBool, Ordering},
    mpsc,
};
use loom::thread;

fn main() {
    let mut model = loom::model::Builder::new();
    model.preemption_bound = Some(3);
    model.check(|| {
        let is_alive = Arc::new(AtomicBool::new(true));
        let request_completed = Arc::new(AtomicBool::new(false));
        let (request_tx, request_rx) = mpsc::channel::<()>();

        let sender_is_alive = Arc::clone(&is_alive);
        let sender_completed = Arc::clone(&request_completed);
        let sender = thread::spawn(move || {
            if !sender_is_alive.load(Ordering::Acquire) {
                sender_completed.store(true, Ordering::Release);
                return;
            }
            if request_tx.send(()).is_err() {
                sender_completed.store(true, Ordering::Release);
                return;
            }
            if !sender_is_alive.load(Ordering::Acquire) {
                sender_completed.store(true, Ordering::Release);
            }
        });

        let worker_is_alive = Arc::clone(&is_alive);
        let worker_completed = Arc::clone(&request_completed);
        let worker = thread::spawn(move || {
            worker_is_alive.store(false, Ordering::Release);
            while request_rx.try_recv().is_ok() {
                worker_completed.store(true, Ordering::Release);
            }
            drop(request_rx);
        });

        sender.join().unwrap();
        worker.join().unwrap();
        assert!(
            request_completed.load(Ordering::Acquire),
            "a successful send was neither drained nor failed"
        );
    });
}

Expected: every accepted request is completed or failed. Observed: Loom panics with Messages leaked. and reports one message, demonstrating the late accepted request.

@lance-gatekeeper lance-gatekeeper Bot added the K-changes Latest Gatekeeper recommendation requests changes. label Aug 24, 2026
@lance-gatekeeper lance-gatekeeper Bot removed the K-changes Latest Gatekeeper recommendation requests changes. label Aug 24, 2026
@Xuanwo
Xuanwo merged commit 687113e into main Aug 24, 2026
46 of 47 checks passed
@Xuanwo
Xuanwo deleted the xuanwo/fix-io-uring-hang branch August 24, 2026 18:10
Xuanwo pushed a commit that referenced this pull request Aug 29, 2026
Fixes #8787.

The uring test module assumed that its process-wide worker pool always
contained a usable worker. Since #8725 correctly reports worker
initialization failures, resource-constrained runners reached that error
during reads and failed the test process under nextest fail-fast.

This change gates the io_uring-dependent cases on the shared worker pool
and returns cleanly when no worker initialized. The regular `file://`
control test remains active, and production io_uring error behavior is
unchanged.

Validation:
- `LANCE_URING_THREAD_COUNT=0 cargo test -p lance-io uring::tests:: --
--test-threads=1`
- `cargo test -p lance-io uring:: -- --test-threads=1`
- `cargo fmt --all -- --check`
- `cargo clippy --all --tests --benches -- -D warnings`

<!-- lance-gatekeeper-fix:v1 agent=8ea9ef0ff8720edc27dfe19dc3c3833c
generation=1 -->

Co-authored-by: Gatefixer <312823363+lance-gatefixer[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-encoding Encoding, IO, file reader/writer bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: io_uring range test can hang indefinitely in nextest

2 participants