fix(oohelperd): enforce timeout for each measurement step (#888)
While working on https://github.com/ooni/probe/issues/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.
This commit is contained in:
		
							parent
							
								
									d711c19b55
								
							
						
					
					
						commit
						b8cc548d41
					
				@ -7,6 +7,7 @@ package main
 | 
				
			|||||||
import (
 | 
					import (
 | 
				
			||||||
	"context"
 | 
						"context"
 | 
				
			||||||
	"sync"
 | 
						"sync"
 | 
				
			||||||
 | 
						"time"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	"github.com/ooni/probe-cli/v3/internal/engine/experiment/webconnectivity"
 | 
						"github.com/ooni/probe-cli/v3/internal/engine/experiment/webconnectivity"
 | 
				
			||||||
	"github.com/ooni/probe-cli/v3/internal/model"
 | 
						"github.com/ooni/probe-cli/v3/internal/model"
 | 
				
			||||||
@ -38,6 +39,9 @@ type dnsConfig struct {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
// dnsDo performs the DNS check.
 | 
					// dnsDo performs the DNS check.
 | 
				
			||||||
func dnsDo(ctx context.Context, config *dnsConfig) {
 | 
					func dnsDo(ctx context.Context, config *dnsConfig) {
 | 
				
			||||||
 | 
						const timeout = 4 * time.Second
 | 
				
			||||||
 | 
						ctx, cancel := context.WithTimeout(ctx, timeout)
 | 
				
			||||||
 | 
						defer cancel()
 | 
				
			||||||
	defer config.Wg.Done()
 | 
						defer config.Wg.Done()
 | 
				
			||||||
	reso := config.NewResolver()
 | 
						reso := config.NewResolver()
 | 
				
			||||||
	defer reso.CloseIdleConnections()
 | 
						defer reso.CloseIdleConnections()
 | 
				
			||||||
 | 
				
			|||||||
@ -10,6 +10,7 @@ import (
 | 
				
			|||||||
	"net/http"
 | 
						"net/http"
 | 
				
			||||||
	"strings"
 | 
						"strings"
 | 
				
			||||||
	"sync"
 | 
						"sync"
 | 
				
			||||||
 | 
						"time"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	"github.com/ooni/probe-cli/v3/internal/engine/experiment/webconnectivity"
 | 
						"github.com/ooni/probe-cli/v3/internal/engine/experiment/webconnectivity"
 | 
				
			||||||
	"github.com/ooni/probe-cli/v3/internal/model"
 | 
						"github.com/ooni/probe-cli/v3/internal/model"
 | 
				
			||||||
@ -44,6 +45,9 @@ type httpConfig struct {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
// httpDo performs the HTTP check.
 | 
					// httpDo performs the HTTP check.
 | 
				
			||||||
func httpDo(ctx context.Context, config *httpConfig) {
 | 
					func httpDo(ctx context.Context, config *httpConfig) {
 | 
				
			||||||
 | 
						const timeout = 15 * time.Second
 | 
				
			||||||
 | 
						ctx, cancel := context.WithTimeout(ctx, timeout)
 | 
				
			||||||
 | 
						defer cancel()
 | 
				
			||||||
	defer config.Wg.Done()
 | 
						defer config.Wg.Done()
 | 
				
			||||||
	req, err := http.NewRequestWithContext(ctx, "GET", config.URL, nil)
 | 
						req, err := http.NewRequestWithContext(ctx, "GET", config.URL, nil)
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
 | 
				
			|||||||
@ -7,6 +7,7 @@ package main
 | 
				
			|||||||
import (
 | 
					import (
 | 
				
			||||||
	"context"
 | 
						"context"
 | 
				
			||||||
	"sync"
 | 
						"sync"
 | 
				
			||||||
 | 
						"time"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	"github.com/ooni/probe-cli/v3/internal/engine/experiment/webconnectivity"
 | 
						"github.com/ooni/probe-cli/v3/internal/engine/experiment/webconnectivity"
 | 
				
			||||||
	"github.com/ooni/probe-cli/v3/internal/model"
 | 
						"github.com/ooni/probe-cli/v3/internal/model"
 | 
				
			||||||
@ -42,6 +43,9 @@ type tcpConfig struct {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
// tcpDo performs the TCP check.
 | 
					// tcpDo performs the TCP check.
 | 
				
			||||||
func tcpDo(ctx context.Context, config *tcpConfig) {
 | 
					func tcpDo(ctx context.Context, config *tcpConfig) {
 | 
				
			||||||
 | 
						const timeout = 10 * time.Second
 | 
				
			||||||
 | 
						ctx, cancel := context.WithTimeout(ctx, timeout)
 | 
				
			||||||
 | 
						defer cancel()
 | 
				
			||||||
	defer config.Wg.Done()
 | 
						defer config.Wg.Done()
 | 
				
			||||||
	dialer := config.NewDialer()
 | 
						dialer := config.NewDialer()
 | 
				
			||||||
	defer dialer.CloseIdleConnections()
 | 
						defer dialer.CloseIdleConnections()
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user