Repository navigation
fix(io): credit the backpressure budget when a request is dropped - #37
Merged
Merged
Conversation
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]>
zehiko
approved these changes
Aug 17, 2026
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. |
Member
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). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
bytes_availis debited when a task is dispatched (IoQueueState::next_task) and was credited in exactly one place — the consumer'srx.mapclosure insubmit_request_standard. That future is afutures::future::Mapwith noDropimpl, and the completion callback discarded a failed send:So abandoning a request — dropping the stream on an error, a cancelled task, runtime shutdown — leaks both the bytes and its
priorities_in_flightentry, permanently.The leaked priority entry is the worse half.
can_deliveradmits 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 aScanScheduleris 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.databecomes anOptionso the consumer can take it whileDropstill runs.The lite scheduler already got this right with its RAII
BackpressureReservation, but lite is only selected forfile+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 ScanSchedulereven documents the "user drops a scan mid-read" scenario — but the exposure grows with how much a single request has in flight. Worth upstreaming tolance-format/lance.