Skip to content

Commit

Permalink
[FAB-7397] Peer deliver panic for nonexistent channel
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
wlahti committed Dec 8, 2017
1 parent 9032266 commit cbc9b49
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
3 changes: 3 additions & 0 deletions core/peer/peer.go
Expand Up @@ -734,6 +734,9 @@ type DeliverSupportManager struct {

func (dsm DeliverSupportManager) GetChain(chainID string) (deliver.Support, bool) {
channel, ok := chains.list[chainID]
if !ok {
return nil, ok
}
return channel.cs, ok
}

Expand Down
15 changes: 15 additions & 0 deletions core/peer/peer_test.go
Expand Up @@ -213,3 +213,18 @@ func TestGetLocalIP(t *testing.T) {
ip := GetLocalIP()
t.Log(ip)
}

func TestDeliverSupportManager(t *testing.T) {
// reset chains for testing
MockInitialize()

manager := &DeliverSupportManager{}
chainSupport, ok := manager.GetChain("fake")
assert.Nil(t, chainSupport, "chain support should be nil")
assert.False(t, ok, "Should not find fake channel")

MockCreateChain("testchain")
chainSupport, ok = manager.GetChain("testchain")
assert.NotNil(t, chainSupport, "chain support should not be nil")
assert.True(t, ok, "Should find testchain channel")
}

0 comments on commit cbc9b49

Please sign in to comment.