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

@ -17,22 +17,22 @@ import (
const maxAcceptableBody = 1 << 24
var (
dialer model.Dialer
endpoint = flag.String("endpoint", ":8080", "Endpoint where to listen")
httpClient model.HTTPClient
resolver model.Resolver
srvcancel context.CancelFunc
srvctx context.Context
srvwg = new(sync.WaitGroup)
endpoint = flag.String("endpoint", ":8080", "Endpoint where to listen")
srvcancel context.CancelFunc
srvctx context.Context
srvwg = new(sync.WaitGroup)
)
func init() {
srvctx, srvcancel = context.WithCancel(context.Background())
}
func newresolver() model.Resolver {
// Implementation note: pin to a specific resolver so we don't depend upon the
// default resolver configured by the box. Also, use an encrypted transport thus
// we're less vulnerable to any policy implemented by the box's provider.
resolver = netxlite.NewParallelDNSOverHTTPSResolver(log.Log, "https://8.8.8.8/dns-query")
httpClient = netxlite.NewHTTPClientWithResolver(log.Log, resolver)
resolver := netxlite.NewParallelDNSOverHTTPSResolver(log.Log, "https://8.8.8.8/dns-query")
return resolver
}
func shutdown(srv *http.Server) {
@ -55,10 +55,14 @@ func main() {
func testableMain() {
mux := http.NewServeMux()
mux.Handle("/", webconnectivity.Handler{
Client: httpClient,
Dialer: dialer,
MaxAcceptableBody: maxAcceptableBody,
Resolver: resolver,
NewClient: func() model.HTTPClient {
return netxlite.NewHTTPClientWithResolver(log.Log, newresolver())
},
NewDialer: func() model.Dialer {
return netxlite.NewDialerWithResolver(log.Log, newresolver())
},
NewResolver: newresolver,
})
srv := &http.Server{Addr: *endpoint, Handler: mux}
srvwg.Add(1)