Skip to content

Commit cbc9b49

Browse files
committed
[FAB-7397] Peer deliver panic for nonexistent channel
Peer deliver panics when it receives a seek info request for a channel that does not exist. This CR checks that the channel exists before accessing the chainSupport for the channel. Change-Id: I6645285b2197250d5a9318dc07ee38451abe3c75 Signed-off-by: Will Lahti <wtlahti@us.ibm.com>
1 parent 9032266 commit cbc9b49

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

core/peer/peer.go

+3
Original file line numberDiff line numberDiff line change
@@ -734,6 +734,9 @@ type DeliverSupportManager struct {
734734

735735
func (dsm DeliverSupportManager) GetChain(chainID string) (deliver.Support, bool) {
736736
channel, ok := chains.list[chainID]
737+
if !ok {
738+
return nil, ok
739+
}
737740
return channel.cs, ok
738741
}
739742

core/peer/peer_test.go

+15
Original file line numberDiff line numberDiff line change
@@ -213,3 +213,18 @@ func TestGetLocalIP(t *testing.T) {
213213
ip := GetLocalIP()
214214
t.Log(ip)
215215
}
216+
217+
func TestDeliverSupportManager(t *testing.T) {
218+
// reset chains for testing
219+
MockInitialize()
220+
221+
manager := &DeliverSupportManager{}
222+
chainSupport, ok := manager.GetChain("fake")
223+
assert.Nil(t, chainSupport, "chain support should be nil")
224+
assert.False(t, ok, "Should not find fake channel")
225+
226+
MockCreateChain("testchain")
227+
chainSupport, ok = manager.GetChain("testchain")
228+
assert.NotNil(t, chainSupport, "chain support should not be nil")
229+
assert.True(t, ok, "Should find testchain channel")
230+
}

0 commit comments

Comments
 (0)