Skip to content

Commit d8d3d92

Browse files
committed
[FAB-2529] Gossip Conn store - thread safety bug
When the gossip comm layer is shutdown, the connection store is also shutdown as a result. While a connection is deleted/added, and the conn store is shutdown at the same time- a concurrent map read-write occures. Change-Id: I6ea84b3fb7e49a616a76d9cc0608a48dacb43bac Signed-off-by: Yacov Manevich <[email protected]>
1 parent 3eaccbd commit d8d3d92

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

gossip/comm/conn.go

+10-2
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,10 @@ func (cs *connectionStore) getConnection(peer *RemotePeer) (*connection, error)
8989

9090
destinationLock.Unlock()
9191

92-
if cs.isClosing {
92+
cs.RLock()
93+
isClosing = cs.isClosing
94+
cs.RUnlock()
95+
if isClosing {
9396
return nil, errors.New("ConnStore is closing")
9497
}
9598

@@ -141,10 +144,15 @@ func (cs *connectionStore) shutdown() {
141144
cs.Lock()
142145
cs.isClosing = true
143146
pkiIds2conn := cs.pki2Conn
147+
148+
var connections2Close []*connection
149+
for _, conn := range pkiIds2conn {
150+
connections2Close = append(connections2Close, conn)
151+
}
144152
cs.Unlock()
145153

146154
wg := sync.WaitGroup{}
147-
for _, conn := range pkiIds2conn {
155+
for _, conn := range connections2Close {
148156
wg.Add(1)
149157
go func(conn *connection) {
150158
cs.closeByPKIid(conn.pkiID)

0 commit comments

Comments
 (0)