From f6b8f159d6ff58d41bfa29b86e5ed050f4fc424e Mon Sep 17 00:00:00 2001 From: Stephen Cathcart Date: Tue, 19 Nov 2024 15:09:02 +0000 Subject: [PATCH 1/2] Fix race condition in pool Co-authored-by: Robsdedude --- neo4j/internal/pool/pool.go | 1 + 1 file changed, 1 insertion(+) diff --git a/neo4j/internal/pool/pool.go b/neo4j/internal/pool/pool.go index 339465cd..f0bd6682 100644 --- a/neo4j/internal/pool/pool.go +++ b/neo4j/internal/pool/pool.go @@ -415,6 +415,7 @@ 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 { + isAlive = false p.unreg(ctx, serverName, c, now) p.log.Infof(log.Pool, p.logId, "Unregistering dead or too old connection to %s", serverName) } From 1d2998429f57b7f2a64aedaeae2568d5b3c56d9b Mon Sep 17 00:00:00 2001 From: Stephen Cathcart Date: Wed, 27 Nov 2024 16:48:51 +0000 Subject: [PATCH 2/2] Added info on fix --- neo4j/internal/pool/pool.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/neo4j/internal/pool/pool.go b/neo4j/internal/pool/pool.go index f0bd6682..cfe04652 100644 --- a/neo4j/internal/pool/pool.go +++ b/neo4j/internal/pool/pool.go @@ -415,6 +415,8 @@ 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)