diff --git a/node.go b/node.go index 706d8f08..de43ed6e 100644 --- a/node.go +++ b/node.go @@ -442,8 +442,10 @@ func (nd *Node) getConnection(timeout time.Duration) (conn *Connection, err erro } if conn == nil { + cc := nd.connectionCount.IncrementAndGet() + // if connection count is limited and enough connections are already created, don't create a new one - if nd.cluster.clientPolicy.LimitConnectionsToQueueSize && nd.connectionCount.IncrementAndGet() > nd.cluster.clientPolicy.ConnectionQueueSize { + if nd.cluster.clientPolicy.LimitConnectionsToQueueSize && cc > nd.cluster.clientPolicy.ConnectionQueueSize { nd.connectionCount.DecrementAndGet() return nil, ErrConnectionPoolEmpty }