packer: don't panic on Put after Wait#414
Merged
Merged
Conversation
When Wait closed packerChan, any in-flight Put would panic with "send on closed channel". Snapshot.Backup has error paths that call PackerManager.Wait while workers are still calling Put (e.g. recordError on a Ctrl+C-interrupted backup), so the panic surfaced in real use. Switch from closing packerChan to a separate closing channel: Put selects on either the send or closing and returns ErrShutdown on shutdown. Run workers also observe closing and flush their in-flight packfile before returning. Wait is now idempotent. Same fix applied to the platar packer for consistency. Adds two regression tests: - TestSeqPackerPutDuringWait races many concurrent Put callers against Wait. Hits "send on closed channel" reliably without the fix. - TestSeqPackerPutAfterWait pins the post-shutdown contract: Put returns an error instead of panicking. Fixes PlakarKorp/plakar#2106 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
There was a problem hiding this comment.
Claude Code Review
This repository is configured for manual code reviews. Comment @claude review to trigger a review and subscribe this PR to future pushes, or @claude review once for a one-time review.
Tip: disable this comment in your organization's Code Review settings.
Contributor
Author
|
Fixes an actual bug, analysis is sound, PR seems ok after an initial review, but I need to discuss this again with @mathieu-plak as I'm not fully convinced about the draining bits. |
Contributor
|
#376 big conflict energy :). |
omar-polo
approved these changes
May 29, 2026
mathieu-plak
approved these changes
May 29, 2026
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
What about the lifecycle bug in snapshot.Backup?
There's an upstream issue too: `importSource` returns early on `importerErr` without waiting for `<-errch`, so workers can still be calling `Put` when `Backup` calls `PackerManager.Wait`. That's a separate fix worth doing on the plakar / snapshot side, but the packer should also not panic regardless of who calls Put with what timing — which is what this PR addresses.
Test plan
(There are two pre-existing `-race` failures in the packer test suite — `TestPackWriter_ConcurrentInternalAccess` and `TestPlatarPackerManager_RunAndWait` — both reproducible on `main` without this change. Out of scope here.)
🤖 Generated with Claude Code