[#331] pool: Avoid connection leak in tree pool with netmap support
To avoid connection leak, call `close()` immediately after connection is established. In regular tree pool, unhealthy connections are handled by background goroutine which calls `redialIfNecessary()` to reestablish connection. Here it is not viable so connection must be close. Signed-off-by: Alex Vanin <a.vanin@yadro.com>
This commit is contained in:
parent
8389887a34
commit
f08a7f0b3c
1 changed files with 10 additions and 0 deletions
|
@ -1032,6 +1032,16 @@ func (p *Pool) getNewTreeClient(ctx context.Context, node netmap.NodeInfo) (*tre
|
|||
newTreeCl := newTreeClient(addr.URIAddr(), p.dialOptions, p.nodeDialTimeout, p.streamTimeout)
|
||||
if err = newTreeCl.dial(ctx); err != nil {
|
||||
p.log(zap.WarnLevel, "failed to dial tree client", zap.String("address", addr.URIAddr()), zap.Error(err))
|
||||
|
||||
// We have to close connection here after failed `dial()`.
|
||||
// This is NOT necessary in object pool and regular tree pool without netmap support, because:
|
||||
// - object pool uses SDK object client which closes connection during `dial()` call by itself,
|
||||
// - regular tree pool is going to reuse connection by calling `redialIfNecessary()`.
|
||||
// Tree pool with netmap support does not operate with background goroutine, so we have to close connection immediately.
|
||||
if err = newTreeCl.close(); err != nil {
|
||||
p.log(zap.WarnLevel, "failed to close recently dialed tree client", zap.String("address", addr.URIAddr()), zap.Error(err))
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue