Skip to content

fix(ledger): prevent panic on snapshot manager shutdown#5380

Open
Ady0333 wants to merge 1 commit intohyperledger:mainfrom
Ady0333:fix/snapshot-mgr-shutdown-race
Open

fix(ledger): prevent panic on snapshot manager shutdown#5380
Ady0333 wants to merge 1 commit intohyperledger:mainfrom
Ady0333:fix/snapshot-mgr-shutdown-race

Conversation

@Ady0333
Copy link
Contributor

@Ady0333 Ady0333 commented Jan 29, 2026

Type of change

  • Bug fix

Description

This PR fixes a shutdown race in the ledger snapshot manager that could cause a peer to panic.

Snapshot generation runs asynchronously in goroutines. If a peer shuts down while a snapshot is still in progress, those goroutines could attempt to send events on the events channel after it has been closed in shutdown(), resulting in a send on closed channel panic.

The fix coordinates snapshot goroutines with shutdown so that no sends occur after shutdown begins.

Additional details

Snapshot goroutines are now tracked and are signaled to stop during shutdown.
shutdown() waits for in-flight snapshot work to finish before closing channels.

Tested locally with go test ./core/ledger/kvledger/...

Release Note

Fixes a shutdown race in the ledger snapshot manager that could cause a peer
panic when snapshots are generated during shutdown.

Signed-off-by: Ady0333 <adityashinde1525@gmail.com>
@Ady0333 Ady0333 requested a review from a team as a code owner January 29, 2026 09:37
@Ady0333
Copy link
Contributor Author

Ady0333 commented Jan 29, 2026

Hi @C0rWin @denyeart @yacovm,

This PR fixes a shutdown race in the snapshot manager where a snapshot goroutine could send on a closed channel and panic.
The change makes shutdown safe even if a snapshot is still in progress.

Thanks for taking a look.

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.

1 participant