Repository navigation
fix(backend): a list scans off the event loop, so progress and cancel stay live - #247
Conversation
… stay live Issue 144: a `list` ran `scan()` inline on the loop that is also the only reader of `Event::Op` and `Event::Request`, so a `read_dir` held by an MTP or network mount froze the transfer card and left `transfercancel` unread. Upstream already landed the cancel half: `spawn_reader` sets the running operation's flag as the line is read (60a07b9, src/backend/events.rs), which is what lets a cancel land whatever the loop is doing. This is the other half, the loop that keeps writing progress: `src/backend/listwork.rs` spawns the scan on its own thread and answers with `Event::List(Done)`, the way a thumbnail or a size posts its own. `Gate` holds every request that arrives while a scan is out and replays it in arrival order once the scan lands, so the sequential command stream (`list A`, `list B`, `paths [0]`) sees the same ordering it did when the scan was inline; a closed stdin waits too, so a listing a script asked for is answered before the process leaves. Limitations, stated honestly: - A second same-backend list cannot overtake the first while it is out. Nothing shipped asks for one: Nav.js's `openWithoutHistory` and the TUI's `Model::open` refuse a navigation while a list is in flight, and dual panes run one backend each. A slow folder delays only the pane that asked for it. - `peek`, `listpaths`, `window`'s `stat_range` and a size/mtime `sort`'s `stat_all` stay synchronous on the loop. None is on the reported path (an MTP folder answers stat from its gio store), and they are named rather than folded in. - No MTP hardware is available here; the proof is a blocked fake gio plus a sparse copy, not a phone. Regression: tests/mtp-scan.sh blocks a fake gio so the scan is provably out, then starts and cancels a 4 GiB sparse copy and requires progress and the cancelled transferdone to be written before the scan's listed line. listwork_tests.rs pins the seams without a mount.
|
Navigate logical layers of code changes, visualize relationships, and explore their blast radius. No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configuration
📒 Files selected for processing (10)
Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 3 remain after this review. 📝 WalkthroughWalkthroughDirectory listing scans now run on a worker thread. The backend event loop continues handling other events while a scan runs, then installs the result and replays deferred requests in arrival order. ChangesAsynchronous listing
Priority: ➖ Normal Estimated code review effort: 3 (Moderate) | ~25 minutes Change: Bug fix · Severity of issue fixed: Medium Sequence Diagram(s)sequenceDiagram
participant Backend as Backend event loop
participant Start as listwork start
participant Worker as Scan worker
participant Events as Event channel
participant Finish as listwork finish
participant Gate as Gate
Backend->>Start: Start listing job
Start->>Worker: Scan requested path
par Scan is pending
Backend->>Events: Process other events
Events-->>Backend: Deliver progress or cancel request
and Scan completes
Worker->>Events: Send Event::List(Done)
end
Events-->>Backend: Deliver Event::List(Done)
Backend->>Finish: Finish and install listing
Backend->>Gate: Retrieve deferred requests in order
Suggested reviewers: Merge Risk: ⚪ Minimal · up to No actionable merge-blocking issue remains in the reviewed listing change; normal checks can proceed. Security Architecture ReviewSecurity architecture risk: 🔵 Low · up to The change improves responsiveness without a demonstrated expansion of privileges or access. Its asynchronous coordination preserves the checked ownership controls, but verification of failure and interruption behavior remains incomplete. Retained concerns Security review detailsSecurity Blast Radius
Trust Boundaries and Controls
Resilience and Maintainability Implications
Hardening Proposals
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
Full details: Docstring CoverageExplanation Docstring coverage is 26.67% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 30 functions across 7 files. (3 skipped: 3 unsupported.)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
merged as authored; a list scans off the event loop so progress and cancel stay live, with a follow-up on top (f3ace52, 816820b, v0.3.10). Thanks @itsmunzir! https://github.com/thisisgm/flea/releases/tag/v0.3.10 |
|
A blocked FUSE source read could still delay cancellation after the listing fix; the separate follow-up at 693a43b518 stops waiting and removes the partial copy in v0.3.11, while physical-phone verification remains tracked under #144. Thanks @itsmunzir! Release. |
Fixes #144.
Problem
Issue #144: moving a large file off an MTP phone showed no progress and Cancel did nothing. The
backend has one event loop, and it was the only reader of
Event::OpandEvent::Request. Alistran
scan()inline on that loop, and aread_dirheld by gvfs/MTP for as long as the device takesholds everything behind it:
transferprogresslines pile up unwritten and atransfercancelsitsunread, so the copy runs to its natural end and the window looks hung.
Solution
Half of this is already on
main:spawn_readersets the running operation's flag as it reads thecancel line (
60a07b9,src/backend/events.rs), so atransfercancelreaches the operation withoutthe loop, and the transfer card's bytes/rate/time-left work is upstream too. This PR is the other half
the report asks for — the loop that keeps writing progress.
src/backend/listwork.rs(new) owns the off-loop scan.listwork::startdoes the walk-end andwatch.beginon the loop exactly as the inline arm did, then spawns the scan on its own thread andreturns the
Job. The scan postsEvent::List(Done)on the loop's one channel, the way a thumbnailor a size posts its own.
listwork::finishdoes what the arm did inline: picker filter, ordering,watch.commit/abandon,adopt,fsinfo.list_arrived,prefetch::first_rows_sent.Gatepreserves request ordering. The protocol is a sequential command stream —tests/protocol.shsends
list A,list B,paths [0]and requires the refusal that only exists if B replaced Abefore
pathsran — so every request that arrives while a scan is out waits inGateand replays inarrival order once the scan lands.
quitor a closed stdin waits too, so a listing a script asked foris still answered before the process leaves, exactly as the inline scan did.
watch.commit/abandonmade current, so a change in the directory just left answers nothing — as itdid when the loop was inside the scan.
st_modeis read on the scan's own thread and rides the answer, so the loop neverstats the stalled mount after the answer lands.
New regression and seams:
tests/mtp-scan.sh(new, registered intests/run-all.sh):FLEA_GIO_BINis a fake gio that blocksuntil the script releases it, so the scan is provably out and blocked before any line is judged. A
4 GiB sparse copy is started and cancelled while the scan is out, and progress and the cancelled
transferdonemust be written before the scan'slistedline. Deterministic — no clock races.src/backend/listwork_tests.rspins the two seams without a mount: a blocked scan does not hold thechannel, and requests queued behind a scan replay in order.
tools/flea-file-budgetrecordssrc/backend/run.rs448 → 460 for the gate and the two extrahandle_linecall sites.Verification
On this revision (base
58fc89f):cargo test— 1144 passed, 0 failed.cargo build— ok.tools/flea-file-budget— passed.tests/js.sh transfer— 39 passed, 0 failed.tests/mtp-scan.sh— passed: fake gio blocked, progress and the cancelledtransferdoneland beforethe scan's
listedline.tests/protocol.sh— 222+ assertions pass.cargo fmt --checkis not claimed as passing: this tree already fails it on pre-existingformatting drift unrelated to this change.
Deterministic smoke:
Limitations
a phone; the reporter's Pixel 7a transfer is not re-run in this PR.
order, which is the only order
protocol.shaccepts, and a client waiting on the olderlistedlinewould otherwise never clear its own
listInFlight. Nothing shipped asks for one:ui/js/Nav.js'sopenWithoutHistoryand the TUI'sModel::openrefuse a navigation while a list is in flight, anddual panes run one backend each (
ui/WindowBody.qml). A slow MTP folder therefore delays only thepane that asked for it; another pane's local folder is a separate backend and answers at once.
peek(preview, columns,network-repair),
listpaths(per-pathlstat),window'sstat_range, and a size/mtimesort'sstat_all. None is on the path the report measured — opening or re-reading a phone folder — and agvfs listing answers stat from its gio store, so a phone folder's default name order pays none of
them.
list-path fix, not a universal "no hangs" claim: a genuine blocking syscall elsewhere onthe loop still blocks it.
Summary by CodeRabbit