fix(outbound): measure HTTP test delay on a warm connection

Since the batched prober replaced the single tester, the reported delay
came from one cold request with keep-alives disabled, so it stacked the
SOCKS handshake, proxy dial, proxy TLS, target TCP and target TLS on top
of the round-trip. Users upgrading from v2.9.4 - whose tester warmed the
connection first and timed a second request - saw several times the real
connection time.

The cold request still proves reachability and supplies the HTTP status
plus the connect/TLS/TTFB breakdown; the delay is now re-measured on a
second request over the kept-alive connection, falling back to the cold
total when the warm request fails. Bodies are drained (bounded) so the
connection returns to the pool, and the batch test asserts both requests
of a probe share one connection.
This commit is contained in:
MHSanaei
2026-07-05 20:19:25 +02:00
parent b6183271da
commit b6873c7a73
4 changed files with 80 additions and 18 deletions
@@ -11,6 +11,7 @@ import (
"net/http/httptest"
"strconv"
"strings"
"sync"
"testing"
"time"
@@ -399,7 +400,12 @@ func TestTestOutboundsTCPLane(t *testing.T) {
}
func TestTestOutboundsHTTPBatchThroughStubSocks(t *testing.T) {
var mu sync.Mutex
requestsPerConn := make(map[string]int)
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
mu.Lock()
requestsPerConn[r.RemoteAddr]++
mu.Unlock()
w.WriteHeader(http.StatusNoContent)
}))
defer srv.Close()
@@ -443,6 +449,19 @@ func TestTestOutboundsHTTPBatchThroughStubSocks(t *testing.T) {
if proc.IsRunning() {
t.Error("temp process not stopped after batch")
}
mu.Lock()
defer mu.Unlock()
totalRequests := 0
for addr, n := range requestsPerConn {
totalRequests += n
if n != 2 {
t.Errorf("connection %s served %d requests, want 2 (warm delay request must reuse the cold request's connection)", addr, n)
}
}
if totalRequests != 4 {
t.Errorf("test URL served %d requests, want 4 (cold + warm per probe)", totalRequests)
}
}
func TestProbeThroughSocksTransportFailure(t *testing.T) {