perf(proxy): avoid unnecessary alloc in Yield (#7708)

This commit is contained in:
Ville Vesilehto
2025-11-24 18:20:30 +02:00
committed by GitHub
parent 63eb9f70e5
commit fe7335e634
2 changed files with 38 additions and 3 deletions

View File

@@ -128,9 +128,15 @@ const yieldTimeout = 25 * time.Millisecond
func (t *Transport) Yield(pc *persistConn) {
pc.used = time.Now() // update used time
// Make this non-blocking, because in the case of a very busy forwarder we will *block* on this yield. This
// blocks the outer go-routine and stuff will just pile up. We timeout when the send fails to as returning
// these connection is an optimization anyway.
// Optimization: Try to return the connection immediately without creating a timer.
// If the receiver is not ready, we fall back to a timeout-based send to avoid blocking forever.
// Returning the connection is just an optimization, so dropping it on timeout is fine.
select {
case t.yield <- pc:
return
default:
}
select {
case t.yield <- pc:
return