Skip to content

Commit

Permalink
[connmgr] remove pending entry on failed connection
Browse files Browse the repository at this point in the history
fix memory leak in connmanager caused by:

* pending entries are not removed on error
* new connection always allocates new struct
* capture id value for callback

Fix by calling Remove in both handleFailedConn callbacks to delete the
item from the pending hash map

Signed-off-by: Christopher Hall <hsw@bitmark.com>
  • Loading branch information
hxw authored and jcvernaleo committed Jan 12, 2023
1 parent 977712a commit 1d77730
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion connmgr/connmanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,11 +210,16 @@ func (cm *ConnManager) handleFailedConn(c *ConnReq) {
log.Debugf("Max failed connection attempts reached: [%d] "+
"-- retrying connection in: %v", maxFailedAttempts,
cm.cfg.RetryDuration)
theId := c.id
time.AfterFunc(cm.cfg.RetryDuration, func() {
cm.Remove(theId)
cm.NewConnReq()
})
} else {
go cm.NewConnReq()
go func(theId uint64) {
cm.Remove(theId)
cm.NewConnReq()
}(c.id)
}
}
}
Expand Down

0 comments on commit 1d77730

Please sign in to comment.