Skip to content

fix(gossip): prevent panic on state provider shutdown - #5378

Merged
yacovm merged 1 commit into
hyperledger:mainfrom
Ady0333:fix/gossip-state-shutdown-race
Jan 27, 2026
Merged

fix(gossip): prevent panic on state provider shutdown#5378
yacovm merged 1 commit into
hyperledger:mainfrom
Ady0333:fix/gossip-state-shutdown-race

Conversation

@Ady0333

@Ady0333 Ady0333 commented Jan 26, 2026

Copy link
Copy Markdown
Contributor

Type of change

  • Bug fix

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.
image

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.

Signed-off-by: Ady0333 <adityashinde1525@gmail.com>
@Ady0333
Ady0333 requested a review from a team as a code owner January 26, 2026 21:16
@Ady0333

Ady0333 commented Jan 26, 2026

Copy link
Copy Markdown
Contributor Author

Hi @C0rWin @denyeart @yacovm,

This PR fixes a shutdown race in the gossip state provider that can cause a send on closed channel panic during peer shutdown.
I’ve kept the change minimal and tested the affected package locally.
Would appreciate your review when you get a chance. Thanks!

@yacovm
yacovm enabled auto-merge (squash) January 27, 2026 09:53
@yacovm
yacovm merged commit d6d621f into hyperledger:main Jan 27, 2026
34 of 37 checks passed
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.

2 participants