From 024de0e4989c2ae306d374aa06b57addc519c2f9 Mon Sep 17 00:00:00 2001 From: Simone Basso Date: Wed, 9 Feb 2022 13:22:01 +0100 Subject: [PATCH] fix(geolocate): enforce 7s timeout for each lookupper (#678) This issue aims at making life slighly better for users impacted by sanctions whose iplookup may be quite slow in case there are timeouts as documented in https://github.com/ooni/probe/issues/1988. --- internal/engine/geolocate/iplookup.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/internal/engine/geolocate/iplookup.go b/internal/engine/geolocate/iplookup.go index 52438a0..3d6d484 100644 --- a/internal/engine/geolocate/iplookup.go +++ b/internal/engine/geolocate/iplookup.go @@ -91,6 +91,10 @@ func makeSlice() []method { func (c ipLookupClient) doWithCustomFunc( ctx context.Context, fn lookupFunc, ) (string, error) { + // Reliability fix: let these mechanisms timeout earlier. + const timeout = 7 * time.Second + ctx, cancel := context.WithTimeout(ctx, timeout) + defer cancel() // Implementation note: we MUST use an HTTP client that we're // sure IS NOT using any proxy. To this end, we construct a // client ourself that we know is not proxied.