Skip to content

fix(io): credit the backpressure budget when a request is dropped - #37

Merged
rerun-rmack merged 1 commit into
release-8.0.0from
rmack/scheduler-credit-budget-on-drop
Aug 17, 2026
Merged

rerun-rmack merged 1 commit into
release-8.0.0from
rmack/scheduler-credit-budget-on-drop

Conversation

@rerun-rmack

Copy link
Copy Markdown
Member

Problem

bytes_avail is debited when a task is dispatched (IoQueueState::next_task) and was credited in exactly one place — the consumer's rx.map closure in submit_request_standard. That future is a futures::future::Map with no Drop impl, and the completion callback discarded a failed send:

let when_all_io_done = move |bytes_and_permits| {
    // We don't care if the receiver has given up so discard the result
    let _ = tx.send(bytes_and_permits);
};

So abandoning a request — dropping the stream on an error, a cancelled task, runtime shutdown — leaks both the bytes and its priorities_in_flight entry, permanently.

The leaked priority entry is the worse half. can_deliver admits any task whose priority is <= priorities_in_flight.min_in_flight(), so one leak pins that floor forever: reads below it bypass backpressure entirely, and reads above it block against a budget that never recovers. Since a ScanScheduler is shared across all files opened on it, the result is a silent permanent stall rather than an error.

Fix

Move the credit into Drop for Response. That covers every path exactly once — consumed normally, dropped before the I/O lands (send fails), dropped after it lands (value discarded inside the channel), and runtime shutdown. data becomes an Option so the consumer can take it while Drop still runs.

The lite scheduler already got this right with its RAII BackpressureReservation, but lite is only selected for file+uring (object_store.rs), so both S3 and local filesystem ran the leaky standard queue.

Testing

cargo test -p lance-io --lib — 172 pass. Clippy clean, fmt applied.

The added test dispatches one request that consumes the whole budget, drops it unpolled, then submits a second at a numerically higher priority. Without the fix it hangs for the full 10 s timeout; with it, it passes.

Note

Found while investigating unrelated scalar-index scan behaviour. It is pre-existing — Drop for ScanScheduler even documents the "user drops a scan mid-read" scenario — but the exposure grows with how much a single request has in flight. Worth upstreaming to lance-format/lance.

The scheduler debits `bytes_avail` when a task is dispatched
(`IoQueueState::next_task`) and credited it in exactly one place: the consumer's
`rx.map` closure in `submit_request_standard`. That future is a
`futures::future::Map` with no `Drop` impl, and the completion callback discarded
a failed send (`let _ = tx.send(...)`), so abandoning a request leaked both the
bytes and its `priorities_in_flight` entry permanently.

The leaked priority entry is the worse half. `IoQueue::can_deliver` admits any
task whose priority is `<= priorities_in_flight.min_in_flight()`, so a leak pins
that floor forever: subsequent reads below it bypass backpressure entirely, while
reads above it block against a budget that never recovers. On a scheduler shared
across a store's files that is a silent, permanent stall rather than an error.

Move the credit into `Drop for Response`, which covers every path — consumed
normally, dropped before the I/O lands (send fails), dropped after it lands
(value discarded in the channel), and runtime shutdown — exactly once each.
`data` becomes an `Option` so the consumer can take it while `Drop` still runs.

The lite scheduler already got this right via its RAII `BackpressureReservation`,
but lite is only selected for `file+uring`, so both S3 and local filesystem ran
the leaky standard queue.

Added test hangs for its full timeout without the fix.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@rerun-rmack
rerun-rmack merged commit 64aeb7c into release-8.0.0 Aug 17, 2026
1 check passed
@rerun-rmack

Copy link
Copy Markdown
Member Author

When looking at forward porting this to 9.0.0 it turns out they already have this fix so this does not need to be cherry-picked or pushed upstream.

@zehiko

zehiko commented Aug 18, 2026

Copy link
Copy Markdown
Member

When looking at forward porting this to 9.0.0 it turns out they already have this fix so this does not need to be cherry-picked or pushed upstream.

nice!

It's still good to have it here as I believe we'll need to go with 0.15.x for the PoC cause of the batching change that is not on main (and shouldn't be).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants