Repository navigation
fix(engine): harden reorder spill against ENOSPC and temp-dir vanish (#2247) - #4158
Merged
Merged
Conversation
Previously `SpillableReorderBuffer` panicked on every disk failure path: ENOSPC during the spill write, a missing spill file at reload time, and short-write fallouts all translated heavy-transfer faults into process crashes that downstream consumers could neither catch nor map to an rsync exit code. This change introduces a typed `SpillError` (capacity vs I/O) and threads `Result` through `insert`, `force_insert`, `next_in_order`, and `drain_ready`. Failed spill writes now return the I/O error and re-insert the offending item so callers can shut down cleanly with exit 11. The implementation also gains an opt-in `with_spill_dir` constructor. When the explicit directory disappears mid-transfer (operator cleanup, tmpfs eviction, container restart), the buffer detects the `NotFound` error, performs a single `create_dir_all` recovery, and retries the write once before surfacing the failure. New tests cover: - ENOSPC injected through the codec, asserting `SpillError::Io` with `ErrorKind::StorageFull` and `is_out_of_space()` true. - Partial-write via a `OneByteWriter` confirming the std `write_all` contract surfaces `WriteZero` rather than silently dropping bytes. - Removing the spill directory mid-test, then asserting the next spill recreates it once (`dir_recreate_events` increments, dir exists). - `create_dir_all` failure when the parent is a regular file - error surfaces without panicking. - A round-trip on the directory-backed flavour to confirm the happy path stays byte-for-byte equivalent to the spooled default. Success-path semantics are unchanged. All pre-existing tests adapt trivially to the new `Result`-returning signatures.
Recovery via `create_dir_all` is only safe when nothing has been spilled yet. With prior items present on the (now-missing) disk a recreate silently loses them; the transfer would continue with a corrupted delivery stream. Return the underlying `NotFound` error in that case so the caller maps it to exit 11 and aborts cleanly. The recoverable "vanish before first spill" path still recreates the directory once and resumes. Split the existing test into two cases (pre-spill recreate succeeds; post-spill vanish surfaces an error and does not increment the recreate counter).
oferchen
added a commit
that referenced
this pull request
May 18, 2026
…2247) (#4158) * fix(engine): harden reorder spill against ENOSPC and temp-dir vanish Previously `SpillableReorderBuffer` panicked on every disk failure path: ENOSPC during the spill write, a missing spill file at reload time, and short-write fallouts all translated heavy-transfer faults into process crashes that downstream consumers could neither catch nor map to an rsync exit code. This change introduces a typed `SpillError` (capacity vs I/O) and threads `Result` through `insert`, `force_insert`, `next_in_order`, and `drain_ready`. Failed spill writes now return the I/O error and re-insert the offending item so callers can shut down cleanly with exit 11. The implementation also gains an opt-in `with_spill_dir` constructor. When the explicit directory disappears mid-transfer (operator cleanup, tmpfs eviction, container restart), the buffer detects the `NotFound` error, performs a single `create_dir_all` recovery, and retries the write once before surfacing the failure. New tests cover: - ENOSPC injected through the codec, asserting `SpillError::Io` with `ErrorKind::StorageFull` and `is_out_of_space()` true. - Partial-write via a `OneByteWriter` confirming the std `write_all` contract surfaces `WriteZero` rather than silently dropping bytes. - Removing the spill directory mid-test, then asserting the next spill recreates it once (`dir_recreate_events` increments, dir exists). - `create_dir_all` failure when the parent is a regular file - error surfaces without panicking. - A round-trip on the directory-backed flavour to confirm the happy path stays byte-for-byte equivalent to the spooled default. Success-path semantics are unchanged. All pre-existing tests adapt trivially to the new `Result`-returning signatures. * fix(engine): refuse silent data loss on temp-dir vanish after spills Recovery via `create_dir_all` is only safe when nothing has been spilled yet. With prior items present on the (now-missing) disk a recreate silently loses them; the transfer would continue with a corrupted delivery stream. Return the underlying `NotFound` error in that case so the caller maps it to exit 11 and aborts cleanly. The recoverable "vanish before first spill" path still recreates the directory once and resumes. Split the existing test into two cases (pre-spill recreate succeeds; post-spill vanish surfaces an error and does not increment the recreate counter). * fix(engine): drop unused dir field from SpillBackend::Directory
oferchen
added a commit
that referenced
this pull request
May 18, 2026
…2247) (#4158) * fix(engine): harden reorder spill against ENOSPC and temp-dir vanish Previously `SpillableReorderBuffer` panicked on every disk failure path: ENOSPC during the spill write, a missing spill file at reload time, and short-write fallouts all translated heavy-transfer faults into process crashes that downstream consumers could neither catch nor map to an rsync exit code. This change introduces a typed `SpillError` (capacity vs I/O) and threads `Result` through `insert`, `force_insert`, `next_in_order`, and `drain_ready`. Failed spill writes now return the I/O error and re-insert the offending item so callers can shut down cleanly with exit 11. The implementation also gains an opt-in `with_spill_dir` constructor. When the explicit directory disappears mid-transfer (operator cleanup, tmpfs eviction, container restart), the buffer detects the `NotFound` error, performs a single `create_dir_all` recovery, and retries the write once before surfacing the failure. New tests cover: - ENOSPC injected through the codec, asserting `SpillError::Io` with `ErrorKind::StorageFull` and `is_out_of_space()` true. - Partial-write via a `OneByteWriter` confirming the std `write_all` contract surfaces `WriteZero` rather than silently dropping bytes. - Removing the spill directory mid-test, then asserting the next spill recreates it once (`dir_recreate_events` increments, dir exists). - `create_dir_all` failure when the parent is a regular file - error surfaces without panicking. - A round-trip on the directory-backed flavour to confirm the happy path stays byte-for-byte equivalent to the spooled default. Success-path semantics are unchanged. All pre-existing tests adapt trivially to the new `Result`-returning signatures. * fix(engine): refuse silent data loss on temp-dir vanish after spills Recovery via `create_dir_all` is only safe when nothing has been spilled yet. With prior items present on the (now-missing) disk a recreate silently loses them; the transfer would continue with a corrupted delivery stream. Return the underlying `NotFound` error in that case so the caller maps it to exit 11 and aborts cleanly. The recoverable "vanish before first spill" path still recreates the directory once and resumes. Split the existing test into two cases (pre-spill recreate succeeds; post-spill vanish surfaces an error and does not increment the recreate counter). * fix(engine): drop unused dir field from SpillBackend::Directory
oferchen
added a commit
that referenced
this pull request
Aug 24, 2026
…2247) (#4158) * fix(engine): harden reorder spill against ENOSPC and temp-dir vanish Previously `SpillableReorderBuffer` panicked on every disk failure path: ENOSPC during the spill write, a missing spill file at reload time, and short-write fallouts all translated heavy-transfer faults into process crashes that downstream consumers could neither catch nor map to an rsync exit code. This change introduces a typed `SpillError` (capacity vs I/O) and threads `Result` through `insert`, `force_insert`, `next_in_order`, and `drain_ready`. Failed spill writes now return the I/O error and re-insert the offending item so callers can shut down cleanly with exit 11. The implementation also gains an opt-in `with_spill_dir` constructor. When the explicit directory disappears mid-transfer (operator cleanup, tmpfs eviction, container restart), the buffer detects the `NotFound` error, performs a single `create_dir_all` recovery, and retries the write once before surfacing the failure. New tests cover: - ENOSPC injected through the codec, asserting `SpillError::Io` with `ErrorKind::StorageFull` and `is_out_of_space()` true. - Partial-write via a `OneByteWriter` confirming the std `write_all` contract surfaces `WriteZero` rather than silently dropping bytes. - Removing the spill directory mid-test, then asserting the next spill recreates it once (`dir_recreate_events` increments, dir exists). - `create_dir_all` failure when the parent is a regular file - error surfaces without panicking. - A round-trip on the directory-backed flavour to confirm the happy path stays byte-for-byte equivalent to the spooled default. Success-path semantics are unchanged. All pre-existing tests adapt trivially to the new `Result`-returning signatures. * fix(engine): refuse silent data loss on temp-dir vanish after spills Recovery via `create_dir_all` is only safe when nothing has been spilled yet. With prior items present on the (now-missing) disk a recreate silently loses them; the transfer would continue with a corrupted delivery stream. Return the underlying `NotFound` error in that case so the caller maps it to exit 11 and aborts cleanly. The recoverable "vanish before first spill" path still recreates the directory once and resumes. Split the existing test into two cases (pre-spill recreate succeeds; post-spill vanish surfaces an error and does not increment the recreate counter). * fix(engine): drop unused dir field from SpillBackend::Directory
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.
Summary
SpillableReorderBufferpanicked on every disk failure path: ENOSPCduring the spill write, a missing spill file at reload time, and short
writes all turned heavy-transfer faults into process crashes that
downstream consumers could neither catch nor map to an rsync exit code.
This change introduces a typed
SpillError(capacity vs I/O) andthreads
Resultthroughinsert,force_insert,next_in_order,and
drain_ready. Spill failures re-insert the offending item andsurface the error so callers shut down cleanly with exit 11
(
FileIo), matching upstream rsync's I/O-failure semantics.A new
with_spill_dirconstructor lets callers point the spill fileat an explicit directory. If that directory disappears mid-transfer
(operator cleanup, tmpfs eviction, container restart) the buffer
attempts a single
create_dir_allrecovery and retries the writeonce - but only when nothing has been spilled yet. With prior items
already on the (now-missing) disk, recovery would silently lose them,
so the
NotFounderror is surfaced instead.Closes #2247.
What this fix handles
write_allerrors nowpropagate up as
SpillError::Iowithis_out_of_space()honouringErrorKind::StorageFull. The just-spilled item is re-inserted sothe caller can shut down without dropping it.
create_dir_allretry, then the original spill is repeated. Thedir_recreate_eventscounter records the recovery.lose unrecoverable items, so the
NotFounderror is surfaced.Write::write_allcontract surfacesWriteZerorather than dropping bytes; the spill record is encodedto an in-memory buffer first so codec failures never leave a
half-written record on disk.
u32::MAX- explicitInvalidDataerrorinstead of silent truncation.
Tests
All in
crates/engine/src/concurrent_delta/spill.rs:enospc_during_spill_propagates_as_io_error- injectsErrorKind::StorageFullvia a codec and asserts the buffersurfaces
SpillError::Iowithis_out_of_space() == true.partial_write_surfaces_as_write_zero- a writer that takes onebyte then returns zero confirms the
write_allcontract surfacesWriteZero.temp_dir_vanish_recreates_when_no_prior_spills- removes thespill directory before the first spill, then asserts exactly one
recreate event and successful continuation.
temp_dir_vanish_after_prior_spills_returns_error- removes thedirectory after a spill has landed, asserts the next spill returns
SpillError::Ioand does not increment the recreate counter.dir_recreate_failure_surfaces_io_error- points the spill dir ata path whose parent is a regular file;
create_dir_allfails andthe error surfaces without panicking.
directory_backed_spill_round_trip- the directory backend yieldsbyte-for-byte the same delivery order as the spooled backend.
spill_error_display_and_source- covers theDisplayandstd::error::Error::sourceimpls.The pre-existing happy-path tests were updated only where the new
Result-returning signatures required (unwrap or.expect); theirassertions are unchanged.
Test plan
cargo fmt --all -- --checkcleancargo clippy --workspace --all-targets --all-features --no-deps -- -D warningscleancargo nextest run -p engine -E 'test(spill)'all green in CI