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

@ -8,6 +8,7 @@ import (
"testing"
"github.com/google/go-cmp/cmp"
"github.com/ooni/probe-cli/v3/internal/model"
"github.com/ooni/probe-cli/v3/internal/netxlite"
)
@ -17,12 +18,14 @@ func TestHTTPDoWithInvalidURL(t *testing.T) {
httpch := make(chan CtrlHTTPResponse, 1)
wg.Add(1)
go HTTPDo(ctx, &HTTPConfig{
Client: http.DefaultClient,
Headers: nil,
MaxAcceptableBody: 1 << 24,
Out: httpch,
URL: "http://[::1]aaaa",
Wg: wg,
NewClient: func() model.HTTPClient {
return http.DefaultClient
},
Out: httpch,
URL: "http://[::1]aaaa",
Wg: wg,
})
// wait for measurement steps to complete
wg.Wait()
@ -39,16 +42,18 @@ func TestHTTPDoWithHTTPTransportFailure(t *testing.T) {
httpch := make(chan CtrlHTTPResponse, 1)
wg.Add(1)
go HTTPDo(ctx, &HTTPConfig{
Client: &http.Client{
Transport: FakeTransport{
Err: expected,
},
},
Headers: nil,
MaxAcceptableBody: 1 << 24,
Out: httpch,
URL: "http://www.x.org",
Wg: wg,
NewClient: func() model.HTTPClient {
return &http.Client{
Transport: FakeTransport{
Err: expected,
},
}
},
Out: httpch,
URL: "http://www.x.org",
Wg: wg,
})
// wait for measurement steps to complete
wg.Wait()