From c5e580b242c2a02df049344f74639d51e21d7e0b Mon Sep 17 00:00:00 2001 From: Martin Coll <145708582+KonixDev@users.noreply.github.com> Date: Wed, 30 Sep 2026 16:40:27 -0300 Subject: [PATCH] =?UTF-8?q?fix(tunnel):=20cortar=20cada=20verificaci=C3=B3?= =?UTF-8?q?n=20a=20los=205=20s=20y=20dar=2060=20s=20en=20total?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Una verificación de /healthz colgada podía comerse 10 s de los 30 del plazo y dejar el túnel en "Conectando…" hasta fallar con "context deadline exceeded". En pruebas reales el túnel tardó 11–24 s en responder, muy cerca del límite viejo. Co-Authored-By: Claude Opus 5.5 --- internal/tunnel/run.go | 7 ++++--- internal/tunnel/run_test.go | 17 +++++++++++++++++ 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/internal/tunnel/run.go b/internal/tunnel/run.go index 6b3194d..f8d194b 100644 --- a/internal/tunnel/run.go +++ b/internal/tunnel/run.go @@ -53,7 +53,7 @@ func childEnv(home string) []string { func Start(ctx context.Context, o Options) (*Tunnel, error) { if o.Timeout == 0 { - o.Timeout = 30 * time.Second + o.Timeout = 60 * time.Second } if o.Verify == nil { o.Verify = verifyHealthz @@ -140,11 +140,12 @@ func verifyHealthz(ctx context.Context, url string) error { var publicDNS = []string{"1.1.1.1:53", "8.8.8.8:53"} +// Cada intento corta a los 5 s: si uno se cuelga mientras la dirección se propaga, el siguiente suele andar. var verifyClient = &http.Client{ - Timeout: 10 * time.Second, + Timeout: 5 * time.Second, Transport: &http.Transport{ DisableKeepAlives: true, - DialContext: (&net.Dialer{Timeout: 10 * time.Second, Resolver: &net.Resolver{ + DialContext: (&net.Dialer{Timeout: 5 * time.Second, Resolver: &net.Resolver{ PreferGo: true, Dial: func(ctx context.Context, network, system string) (net.Conn, error) { d := net.Dialer{Timeout: 2 * time.Second} diff --git a/internal/tunnel/run_test.go b/internal/tunnel/run_test.go index 8b39e52..f156dbd 100644 --- a/internal/tunnel/run_test.go +++ b/internal/tunnel/run_test.go @@ -3,6 +3,8 @@ package tunnel import ( "context" "errors" + "net/http" + "net/http/httptest" "os" "os/exec" "path/filepath" @@ -91,6 +93,21 @@ func TestStartVerifyFails(t *testing.T) { } } +// Una comprobación colgada no puede comerse el plazo entero: tiene que cortar rápido y reintentar. +func TestVerifyHealthzDoesNotHang(t *testing.T) { + block := make(chan struct{}) + srv := httptest.NewServer(http.HandlerFunc(func(http.ResponseWriter, *http.Request) { <-block })) + defer srv.Close() + defer close(block) + start := time.Now() + if err := verifyHealthz(context.Background(), srv.URL); err == nil { + t.Fatal("un servidor que no contesta pasó la verificación") + } + if d := time.Since(start); d > 6*time.Second { + t.Fatalf("la comprobación esperó %v; tiene que cortar antes para poder reintentar", d) + } +} + func TestChildDiesOnItsOwn(t *testing.T) { t.Setenv("FAKE_MODE", "die") tun, err := Start(context.Background(), Options{Bin: fakeBin, Port: 8080, Timeout: 5 * time.Second, Verify: okVerify})