refactor(netx/resolver): add CloseIdleConnections to RoundTripper (#501)

While there, also change to pointer receiver and use internal
testing for what are clearly unit tests.

Part of https://github.com/ooni/probe/issues/1591.
This commit is contained in:
Simone Basso 2021-09-09 20:49:12 +02:00 committed by GitHub
commit 1eb9e8c9b0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
13 changed files with 203 additions and 115 deletions

View file

@ -22,6 +22,9 @@ type RoundTripper interface {
// Address is the address of the round tripper (e.g. "1.1.1.1:853")
Address() string
// CloseIdleConnections closes idle connections.
CloseIdleConnections()
}
// SerialResolver is a resolver that first issues an A query and then
@ -81,7 +84,7 @@ func (r SerialResolver) roundTripWithRetry(
}
errorslist = append(errorslist, err)
var operr *net.OpError
if errors.As(err, &operr) == false || operr.Timeout() == false {
if !errors.As(err, &operr) || !operr.Timeout() {
// The first error is the one that is most likely to be caused
// by the network. Subsequent errors are more likely to be caused
// by context deadlines. So, the first error is attached to an