Skip to content
This repository was archived by the owner on Apr 25, 2025. It is now read-only.

Commit 40ef627

Browse files
committed
[FAB-8780] Recover a cached conn from server HUP
This change enables the janitor to detect when the connector has already removed a connection due to HUP. In this case, the connection needs to be removed from sweep consideration. Change-Id: Ie1333f09d066126affcacfae410ba5612eba7733 Signed-off-by: Troy Ronda <troy@troyronda.com>
1 parent a990267 commit 40ef627

File tree

1 file changed

+25
-2
lines changed

1 file changed

+25
-2
lines changed

pkg/fab/comm/connector.go

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -283,8 +283,7 @@ func janitor(sweepTime time.Duration, idleTime time.Duration, wg *sync.WaitGroup
283283
flush(conns)
284284
return
285285
case c := <-conn:
286-
logger.Debugf("updating connection in connection janitor")
287-
conns[c.target] = c
286+
cache(conns, c)
288287
case <-ticker.C:
289288
rm := sweep(conns, idleTime)
290289
for _, target := range rm {
@@ -301,6 +300,30 @@ func janitor(sweepTime time.Duration, idleTime time.Duration, wg *sync.WaitGroup
301300
}
302301
}
303302

303+
func cache(conns map[string]*cachedConn, updateConn *cachedConn) {
304+
305+
c, ok := conns[updateConn.target]
306+
if ok && updateConn.lastClose.IsZero() && updateConn.conn.GetState() == connectivity.Shutdown {
307+
logger.Debugf("connection shutdown detected in connection janitor")
308+
// We need to remove the connection from sweep consideration immediately
309+
// since the connector has already removed it. Otherwise we can have a race
310+
// between shutdown and creating a connection concurrently.
311+
delete(conns, updateConn.target)
312+
return
313+
}
314+
315+
if !ok {
316+
logger.Debugf("new connection in connection janitor")
317+
} else if c.conn != updateConn.conn {
318+
logger.Debugf("connection change in connection janitor")
319+
c.conn.Close() // Not blocking
320+
} else {
321+
logger.Debugf("updating existing connection in connection janitor")
322+
}
323+
324+
conns[updateConn.target] = updateConn
325+
}
326+
304327
func flush(conns map[string]*cachedConn) {
305328
for _, c := range conns {
306329
logger.Debugf("connection janitor closing connection [%s]", c.target)

0 commit comments

Comments
 (0)