Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TestHostClientMaxConnWaitTimeoutError test case sometimes fails #1832

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion client.go
Original file line number Diff line number Diff line change
Expand Up @@ -1552,6 +1552,7 @@ func (c *HostClient) acquireConn(reqTimeout time.Duration, connectionClose bool)
case <-w.ready:
return w.conn, w.err
case <-tc.C:
c.connsWait.failedWaiters.Add(1)
if timeoutOverridden {
return nil, ErrTimeout
}
Expand Down Expand Up @@ -1697,6 +1698,7 @@ func (c *HostClient) decConnsCount() {
dialed = true
break
}
c.connsWait.failedWaiters.Add(-1)
}
}
if !dialed {
Expand Down Expand Up @@ -1751,6 +1753,7 @@ func (c *HostClient) releaseConn(cc *clientConn) {
delivered = w.tryDeliver(cc, nil)
break
}
c.connsWait.failedWaiters.Add(-1)
}
}
if !delivered {
Expand Down Expand Up @@ -2106,11 +2109,17 @@ type wantConnQueue struct {
head []*wantConn
tail []*wantConn
headPos int
// failedWaiters is the number of waiters in the head or tail queue,
// but is invalid.
// These state waiters cannot truly be considered as waiters; the current
// implementation does not immediately remove them when they become
// invalid but instead only marks them.
failedWaiters atomic.Int64
}

// len returns the number of items in the queue.
func (q *wantConnQueue) len() int {
return len(q.head) - q.headPos + len(q.tail)
return len(q.head) - q.headPos + len(q.tail) - int(q.failedWaiters.Load())
}

// pushBack adds w to the back of the queue.
Expand Down Expand Up @@ -2154,6 +2163,7 @@ func (q *wantConnQueue) clearFront() (cleaned bool) {
return cleaned
}
q.popFront()
q.failedWaiters.Add(-1)
cleaned = true
}
}
Expand Down