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.
This commit is contained in:
Simone Basso 2022-02-09 13:22:01 +01:00 committed by GitHub
parent f7fd29b246
commit 024de0e498
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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.