From e7b779c1746fc2e0bf1e9284a0df8f3e871ccea2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=86=89=E5=B0=8F=E9=BE=99?= Date: Tue, 7 Jan 2020 01:15:25 +0800 Subject: [PATCH] Fixed memory leak of connection (#165) Signed-off-by: xiaolong.ran --- pulsar/internal/connection_pool.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/pulsar/internal/connection_pool.go b/pulsar/internal/connection_pool.go index 14f775364e23e..b91324ad05fd6 100644 --- a/pulsar/internal/connection_pool.go +++ b/pulsar/internal/connection_pool.go @@ -68,11 +68,13 @@ func (p *connectionPool) GetConnection(logicalAddr *url.URL, physicalAddr *url.U } // Try to create a new connection - newCnx, wasCached := p.pool.LoadOrStore(logicalAddr.Host, - newConnection(logicalAddr, physicalAddr, p.tlsOptions, p.connectionTimeout, p.auth)) + newConnection := newConnection(logicalAddr, physicalAddr, p.tlsOptions, p.connectionTimeout, p.auth) + newCnx, wasCached := p.pool.LoadOrStore(logicalAddr.Host, newConnection) cnx := newCnx.(*connection) if !wasCached { cnx.start() + } else { + newConnection.Close() } if err := cnx.waitUntilReady(); err != nil {