Fix nil pointer panic in Deliverer.Stop() during leader election#5420
Open
Ady0333 wants to merge 1 commit intohyperledger:mainfrom
Open
Fix nil pointer panic in Deliverer.Stop() during leader election#5420Ady0333 wants to merge 1 commit intohyperledger:mainfrom
Ady0333 wants to merge 1 commit intohyperledger:mainfrom
Conversation
Deliverer.Stop() and BFTDeliverer.Stop() unconditionally called d.blockReceiver.Stop() without a nil guard. blockReceiver is only set inside DeliverBlocks() after a successful orderer connection, so calling Stop() before that connection succeeds (e.g. when a peer renounces gossip leadership while the orderer is unreachable) caused a nil pointer dereference and panicked the peer. Add a nil check before calling blockReceiver.Stop() in both paths. Add regression tests that call Stop() before DeliverBlocks() is ever started to confirm no panic occurs. Signed-off-by: Ady0333 <adityashinde1525@gmail.com>
Contributor
Author
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
Fixed a nil pointer dereference that crashes the peer when
Stop()is called before a successful orderer connection.The issue occurs during normal gossip leader election when the orderer is unreachable. When a peer renounces leadership, it calls
StopDeliverForChannel()→Deliverer.Stop(), which unconditionally dereferencesd.blockReceiver.Stop(). However,blockReceiveris only initialized insideDeliverBlocks()after a successful gRPC connection to an orderer. IfStop()is called before that connection succeeds, the peer panics and crashes.I've added a nil check before calling
blockReceiver.Stop()in bothDeliverer.Stop()andBFTDeliverer.Stop(). The fix is safe becauseclose(d.DoneC)already signalsDeliverBlocks()to exit, and the mutex protects against races.I've also added regression tests that reproduce the crash scenario - calling
Stop()beforeDeliverBlocks()starts. These tests panic without the fix and pass with it.Additional details
This affects production networks during:
The crash is not a shutdown-only bug - it happens during normal operation when leadership flips while orderers are down.
Related issues
Fixes the peer crash during gossip leader election when orderers are unreachable.