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) }