fix(oohelperd): use throw-away HTTPClient, Dialer, Resolver (#833)

This diff modifies the implementation of oohelperd in the master branch
to always use throw-away HTTPClient, Dialer, and Resolver.

The rationale of this change is to ensure we're not hitting limits of the
HTTPClient regarding the max number of connections per host.

This issue is described at https://github.com/ooni/probe/issues/2182.

While there, it feels more correct to use throw-away Dialer and Resolver.

We have a different patch for the release/3.15 branch because of
netx-related refactorings: https://github.com/ooni/probe-cli/pull/832.
This commit is contained in:
Simone Basso 2022-07-05 18:41:35 +02:00 committed by GitHub
commit a4d17085f5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 87 additions and 60 deletions

View file

@ -19,9 +19,9 @@ type CtrlHTTPResponse = webconnectivity.ControlHTTPRequestResult
// HTTPConfig configures the HTTP check.
type HTTPConfig struct {
Client model.HTTPClient
Headers map[string][]string
MaxAcceptableBody int64
NewClient func() model.HTTPClient
Out chan CtrlHTTPResponse
URL string
Wg *sync.WaitGroup
@ -50,7 +50,9 @@ func HTTPDo(ctx context.Context, config *HTTPConfig) {
}
}
}
resp, err := config.Client.Do(req)
clnt := config.NewClient()
defer clnt.CloseIdleConnections()
resp, err := clnt.Do(req)
if err != nil {
config.Out <- CtrlHTTPResponse{ // fix: emit -1 like old test helper does
BodyLength: -1,