Skip to content

Commit

Permalink
fix(oohelperd): enforce timeout for each measurement step
Browse files Browse the repository at this point in the history
While working on ooni/probe#2237, I noticed
there's no enforced timeout for measurement tasks.

So, this diff introduces the following timeouts:

1. use a 4 seconds timeout for the DNS lookup;

2. use a 10 seconds timeout for TCP;

3. use a 15 seconds timeout for HTTP.

They are a bit stricter than what we have on the probe because the TH
should supposedly have better bandwidth and connectivity.
  • Loading branch information
bassosimone committed Aug 28, 2022
1 parent d711c19 commit 670ee23
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
4 changes: 4 additions & 0 deletions internal/cmd/oohelperd/dns.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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()
Expand Down
4 changes: 4 additions & 0 deletions internal/cmd/oohelperd/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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 {
Expand Down
4 changes: 4 additions & 0 deletions internal/cmd/oohelperd/tcpconnect.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit 670ee23

Please sign in to comment.