Skip to content

Commit

Permalink
[FAB-8964]Log Warning instead of panic
Browse files Browse the repository at this point in the history
Change-Id: Id07a3c11d90e2a1cbb46314f6ad24e5b33bc4b32
Signed-off-by: biljana lukovic <biljana.lukovic@securekey.com>
Signed-off-by: Troy Ronda <troy@troyronda.com>
  • Loading branch information
biljanaLukovic authored and troyronda committed Mar 20, 2018
1 parent 406f79d commit 73c53c4
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 16 deletions.
46 changes: 31 additions & 15 deletions pkg/fab/comm/connector.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,23 +76,27 @@ func (cc *CachingConnector) Close() {
cc.lock.Lock()
defer cc.lock.Unlock()

if cc.janitorDone != nil {
logger.Debug("closing caching GRPC connector")

select {
case <-cc.janitorClosed:
logger.Debugf("janitor not running")
default:
logger.Debugf("janitor running")
cc.janitorDone <- true
cc.waitgroup.Wait()
}
// Safety check to see if the connector has been closed. This represents a
// bug in the calling code, but it's not good to panic here.
if cc.janitorDone == nil {
logger.Warn("Trying to close connector after already closed")
return
}
logger.Debug("closing caching GRPC connector")

close(cc.janitorChan)
close(cc.janitorClosed)
close(cc.janitorDone)
cc.janitorDone = nil
select {
case <-cc.janitorClosed:
logger.Debugf("janitor not running")
default:
logger.Debugf("janitor running")
cc.janitorDone <- true
cc.waitgroup.Wait()
}

close(cc.janitorChan)
close(cc.janitorClosed)
close(cc.janitorDone)
cc.janitorDone = nil
}

// DialContext is a wrapper for grpc.DialContext where connections are cached.
Expand All @@ -119,6 +123,18 @@ func (cc *CachingConnector) ReleaseConn(conn *grpc.ClientConn) {
cc.lock.Lock()
defer cc.lock.Unlock()

// Safety check to see if the connector has been closed. This represents a
// bug in the calling code, but it's not good to panic here.
if cc.janitorDone == nil {
logger.Warn("Trying to release connection after connector closed")

if conn.GetState() != connectivity.Shutdown {
logger.Warn("Connection is not shutdown, trying to close ...")
conn.Close()
}
return
}

cconn, ok := cc.index[conn]
if !ok {
logger.Warnf("connection not found [%p]", conn)
Expand Down
12 changes: 12 additions & 0 deletions pkg/fab/comm/connector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,18 @@ func TestConnectorDoubleClose(t *testing.T) {
connector.Close()
}

func TestReleaseAfterClose(t *testing.T) {
connector := NewCachingConnector(normalSweepTime, normalIdleTime)
defer connector.Close()

ctx, cancel := context.WithTimeout(context.Background(), normalTimeout)
conn1, err := connector.DialContext(ctx, endorserAddr[0], grpc.WithInsecure())
cancel()
assert.Nil(t, err, "DialContext should have succeeded")
connector.Close()
assert.Equal(t, connectivity.Shutdown, conn1.GetState(), "connection should be shutdown")
connector.ReleaseConn(conn1)
}
func TestConnectorHappyFlushNumber1(t *testing.T) {
connector := NewCachingConnector(normalSweepTime, normalIdleTime)
defer connector.Close()
Expand Down
2 changes: 1 addition & 1 deletion pkg/fab/events/eventhubclient/connection/connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,9 @@ func (c *EventHubConnection) Receive(eventch chan<- interface{}) {
eventch <- clientdisp.NewDisconnectedEvent(err)
break
}

logger.Debugf("Got event %#v", in)
eventch <- in

}
logger.Debugf("Exiting stream listener")
}

0 comments on commit 73c53c4

Please sign in to comment.