Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix memory leak in connmanager #1576

Merged
merged 1 commit into from
Jan 12, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
[connmgr] remove pending entry on failed connection
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 committed Jan 11, 2023
commit 29900c7aee1025a116144539cbeee76f136f0d1e
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