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.
This commit is contained in:
newacorn
2024-08-21 05:24:01 +08:00
committed by GitHub
parent 3cdc6f124a
commit 5cc0ea1ec3
+11 -1
View File
@@ -1749,7 +1749,17 @@ func (c *HostClient) releaseConn(cc *clientConn) {
w := q.popFront()
if w.waiting() {
delivered = w.tryDeliver(cc, nil)
break
// This is the last resort to hand over conCount sema.
// We must ensure that there are no valid waiters in connsWait
// when we exit this loop.
//
// We did not apply the same looping pattern in the decConnsCount
// method because it needs to create a new time-spent connection,
// and the decConnsCount call chain will inevitably reach this point.
// When MaxConnWaitTimeout>0.
if delivered {
break
}
}
c.connsWait.failedWaiters.Add(-1)
}