Skip to content

fix(packer): write no pack after a failed pack write - #690

Open
stefanwichmann wants to merge 2 commits into
rustic-rs:mainfrom
stefanwichmann:packer-stop-after-failed-write
Open

stefanwichmann wants to merge 2 commits into
rustic-rs:mainfrom
stefanwichmann:packer-stop-after-failed-write

Conversation

@stefanwichmann

@stefanwichmann stefanwichmann commented Dec 4, 2026 •

Copy link
Copy Markdown
Contributor

Closes #689

A failed pack write no longer leaves the packer writing every other pack, each with the backend's full retries, before the error returns. Two commits, one per cause in #689.

fix(packer): write no pack after a pack write failed

The write stage in Actor::new remembers a failed write and skips every later pack with an error that try_for_each, already stopped at the first one, never sees. pariter's readahead threads still pull the queued packs, but nothing is written.

fix(packer): save no unfinished pack from a packer dropped unfinalized

Packer::finalize sets a flag before it closes the channel, and the thread finalizes the RawPacker only when the flag is set. A packer dropped without finalize, as the tree packer is when the data packer fails, saves nothing. Packs already handed to the writer are written as before, unless one fails. This changes what #672 kept ("It still happens, as before"): that write was for a pack no snapshot references.

Tests

Two unit tests in blob/packer.rs, next to #672's, on its SlowPackBackend:

  • no_pack_write_starts_after_a_failed_one: the first of four queued pack writes fails; one write starts. Without the change, four do.
  • a_packer_dropped_without_finalize_does_not_save_its_unfinished_pack: dropping a packer holding a blob smaller than a pack starts no write, and finalizing one starts one. Without the change, the drop writes the pack.

Checked against a REST server that stops reading uploads: before, 6 to 15 pack uploads depending on the source size; after, the three attempts at the first pack.

🤖 Generated with Claude Code

stefanwichmann and others added 2 commits December 4, 2026 21:49
`Actor::new` runs the pack writes in a `readahead_scoped` stage. When a
write fails, `try_for_each` stops, but `pariter`'s readahead threads go
on pulling items and drop each send's error (`let _ = tx.send(i)`), so
the write stage writes every queued pack, each with the backend's full
retries. Since rustic-rs#672, `finalize` waits for all of them before it returns
the first error.

Against a server that stops reading uploads, with a 600 s request bound
and two retries, each further pack costs another half hour, and a
backup's end grows with its data instead of ending after one pack's
attempts.

The write stage now remembers a failed write and skips every later
pack with an error that `try_for_each`, already stopped, never sees.

A unit test fails the first of four queued pack writes and asserts that
no other write starts; without the change, all four do.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A packer's thread finalizes its `RawPacker` once its channel closes,
whether `finalize` closed it or the last clone was dropped. On the error
path that is the second: when the data packer fails, `Archiver::archive`
returns before `tree_archiver.finalize`, and the dropped tree packer
still saves its unfinished pack, with the backend's full retries; rustic-rs#672
made the drop wait for that write.

Against a server that stops reading uploads, that is one more pack's
attempts after the backup has already failed, for a pack no snapshot
references.

`finalize` now sets a flag the thread reads after the channel closes,
and a packer dropped without it saves nothing. Packs already handed to
the writer are written as before, unless one fails.

A unit test drops a packer holding a blob smaller than a pack and
asserts that no write starts, then finalizes one and asserts that one
does; without the change, the drop writes the pack.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

A failed pack write leaves the packer writing every other pack, each with full retries

1 participant