fix(gossip): prevent panic on state provider shutdown - #5378
Merged
Conversation
Signed-off-by: Ady0333 <adityashinde1525@gmail.com>
Contributor
Author
yacovm
approved these changes
Jan 27, 2026
yacovm
enabled auto-merge (squash)
January 27, 2026 09:53
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.
Type of change
Description
This PR fixes a race condition in the gossip state provider that can cause a peer to panic during shutdown.
Gossip message handlers run in separate goroutines and may still be processing messages when Stop() is called. During shutdown, Stop() closes the state request and response channels. If an in-flight handler tries to send on these channels after they are closed, the peer crashes with panic: send on closed channel.
The fix ensures that message handlers respect the shutdown signal and exit cleanly instead of panicking.
Additional details
Channel sends in directMessage() are now guarded using select statements that also listen on stopCh.
This makes shutdown safe while preserving existing behavior during normal operation.
Example:
select { case s.stateRequestCh <- msg: case <-s.stopCh: }Tested locally with

go test ./gossip/state/....The affected package passes cleanly. Broader gossip/service
tests fail due to missing orderer endpoints in the local environment.
Release Note
Fixes a race condition in the gossip state provider that could cause a peer to
panic during shutdown when gossip messages are in flight.