Skip to content

Fix panic on send to closed channel during snapshot shutdown#5384

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

Fix panic on send to closed channel during snapshot shutdown#5384
Ady0333 wants to merge 1 commit intohyperledger:mainfrom
Ady0333:fix-snapshot-shutdown-race

Conversation

@Ady0333
Copy link
Contributor

@Ady0333 Ady0333 commented Feb 3, 2026

Type of change

  • Bug fix

Description

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

Snapshot generation runs asynchronously in background goroutines. If the peer shuts down while a snapshot is still in progress, snapshotMgr.shutdown() could close internal channels before those goroutines finish, leading to a send on closed channel panic.

The fix coordinates shutdown with in-flight snapshot goroutines so shutdown is safe even when snapshot generation is ongoing.

Additional details

The snapshot manager now signals shutdown to background goroutines and waits for them to exit before closing channels.

Tested locally with go test ./core/ledger/kvledger/....
Also ran go test ./core/ledger/kvledger -run Snapshot -v
image

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 February 3, 2026 10:02
@Ady0333
Copy link
Contributor Author

Ady0333 commented Feb 3, 2026

Hi @corwin @denyeart @yacovm ,
This PR fixes the shutdown panic and snapshot tests pass locally.
Please let me know if anything else is needed. Thanks!

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