Skip to content

Commit 5cc0ea1

Browse files
authored
Fix the MaxConns semaphore issue in HostClient. (#1831)
Fix the MaxConns semaphore issue in HostClient. Currently, the conns length and connsCount count in HostClient do not correctly implement the MaxConns semaphore mechanism. This fix ensures that the waiter wake-up chain does not break.
1 parent 3cdc6f1 commit 5cc0ea1

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

client.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1749,7 +1749,17 @@ func (c *HostClient) releaseConn(cc *clientConn) {
17491749
w := q.popFront()
17501750
if w.waiting() {
17511751
delivered = w.tryDeliver(cc, nil)
1752-
break
1752+
// This is the last resort to hand over conCount sema.
1753+
// We must ensure that there are no valid waiters in connsWait
1754+
// when we exit this loop.
1755+
//
1756+
// We did not apply the same looping pattern in the decConnsCount
1757+
// method because it needs to create a new time-spent connection,
1758+
// and the decConnsCount call chain will inevitably reach this point.
1759+
// When MaxConnWaitTimeout>0.
1760+
if delivered {
1761+
break
1762+
}
17531763
}
17541764
c.connsWait.failedWaiters.Add(-1)
17551765
}

0 commit comments

Comments
 (0)