diff --git a/internal/cmd/oohelperd/dns.go b/internal/cmd/oohelperd/dns.go index 7f71e83..6b64940 100644 --- a/internal/cmd/oohelperd/dns.go +++ b/internal/cmd/oohelperd/dns.go @@ -7,6 +7,7 @@ package main import ( "context" "sync" + "time" "github.com/ooni/probe-cli/v3/internal/engine/experiment/webconnectivity" "github.com/ooni/probe-cli/v3/internal/model" @@ -38,6 +39,9 @@ type dnsConfig struct { // dnsDo performs the DNS check. func dnsDo(ctx context.Context, config *dnsConfig) { + const timeout = 4 * time.Second + ctx, cancel := context.WithTimeout(ctx, timeout) + defer cancel() defer config.Wg.Done() reso := config.NewResolver() defer reso.CloseIdleConnections() diff --git a/internal/cmd/oohelperd/http.go b/internal/cmd/oohelperd/http.go index d177d3c..596404c 100644 --- a/internal/cmd/oohelperd/http.go +++ b/internal/cmd/oohelperd/http.go @@ -10,6 +10,7 @@ import ( "net/http" "strings" "sync" + "time" "github.com/ooni/probe-cli/v3/internal/engine/experiment/webconnectivity" "github.com/ooni/probe-cli/v3/internal/model" @@ -44,6 +45,9 @@ type httpConfig struct { // httpDo performs the HTTP check. func httpDo(ctx context.Context, config *httpConfig) { + const timeout = 15 * time.Second + ctx, cancel := context.WithTimeout(ctx, timeout) + defer cancel() defer config.Wg.Done() req, err := http.NewRequestWithContext(ctx, "GET", config.URL, nil) if err != nil { diff --git a/internal/cmd/oohelperd/tcpconnect.go b/internal/cmd/oohelperd/tcpconnect.go index 8611893..b2df17b 100644 --- a/internal/cmd/oohelperd/tcpconnect.go +++ b/internal/cmd/oohelperd/tcpconnect.go @@ -7,6 +7,7 @@ package main import ( "context" "sync" + "time" "github.com/ooni/probe-cli/v3/internal/engine/experiment/webconnectivity" "github.com/ooni/probe-cli/v3/internal/model" @@ -42,6 +43,9 @@ type tcpConfig struct { // tcpDo performs the TCP check. func tcpDo(ctx context.Context, config *tcpConfig) { + const timeout = 10 * time.Second + ctx, cancel := context.WithTimeout(ctx, timeout) + defer cancel() defer config.Wg.Done() dialer := config.NewDialer() defer dialer.CloseIdleConnections()