From a9c3fc53311adbb0405798931d7829e257513a7f Mon Sep 17 00:00:00 2001 From: Stephen Cathcart Date: Wed, 27 Nov 2024 19:03:31 +0000 Subject: [PATCH] Fix race condition in pool (#610) * Fix race condition in pool Co-authored-by: Robsdedude --------- Co-authored-by: Robsdedude --- neo4j/internal/pool/pool.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/neo4j/internal/pool/pool.go b/neo4j/internal/pool/pool.go index 339465cd..cfe04652 100644 --- a/neo4j/internal/pool/pool.go +++ b/neo4j/internal/pool/pool.go @@ -415,6 +415,9 @@ func (p *Pool) Return(ctx context.Context, c idb.Connection) { // Shouldn't return a too old or dead connection back to the pool if !isAlive || age >= p.config.MaxConnectionLifetime { + // Fix for race condition where expired connections could be reused or closed concurrently. + // See: https://github.com/neo4j/neo4j-go-driver/issues/574 + isAlive = false p.unreg(ctx, serverName, c, now) p.log.Infof(log.Pool, p.logId, "Unregistering dead or too old connection to %s", serverName) }