Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions internal/tunnel/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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}
Expand Down
17 changes: 17 additions & 0 deletions internal/tunnel/run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package tunnel
import (
"context"
"errors"
"net/http"
"net/http/httptest"
"os"
"os/exec"
"path/filepath"
Expand Down Expand Up @@ -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})
Expand Down
Loading