Skip to content

Commit

Permalink
Pull request 382: 7357-doh-close-iddle-conns
Browse files Browse the repository at this point in the history
Updates AdguardTeam/AdGuardHome#7357.

Squashed commit of the following:

commit 4170865
Author: Stanislav Chzhen <[email protected]>
Date:   Thu Nov 28 16:53:39 2024 +0300

    upstream: imp docs

commit 0e89c40
Author: Stanislav Chzhen <[email protected]>
Date:   Thu Nov 28 15:57:38 2024 +0300

    upstream: doh close iddle conns
  • Loading branch information
schzhn committed Nov 28, 2024
1 parent 129cf05 commit f901a5f
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions upstream/doh.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ type dnsOverHTTPS struct {
// quicConfMu protects quicConf.
quicConfMu *sync.Mutex

// transportH2 is an HTTP/2 transport if any.
transportH2 *http2.Transport

// addrRedacted is the redacted string representation of addr. It is saved
// separately to reduce allocations during logging and error reporting.
addrRedacted string
Expand Down Expand Up @@ -209,12 +212,14 @@ func (p *dnsOverHTTPS) Close() (err error) {
return err
}

// closeClient cleans up resources used by client if necessary. Note, that at
// this point it should only be done for HTTP/3 as it may leak due to keep-alive
// connections.
// closeClient cleans up resources used by client if necessary. Note that this
// should be done for HTTP/3, as it can lead to resource leaks due to keep-alive
// connections, and for HTTP/2 due to idle connections.
func (p *dnsOverHTTPS) closeClient(client *http.Client) (err error) {
if isHTTP3(client) {
return client.Transport.(io.Closer).Close()
} else if p.transportH2 != nil {
p.transportH2.CloseIdleConnections()
}

return nil
Expand Down Expand Up @@ -474,14 +479,13 @@ func (p *dnsOverHTTPS) createTransport() (t http.RoundTripper, err error) {
// Explicitly configure transport to use HTTP/2.
//
// See https://github.com/AdguardTeam/dnsproxy/issues/11.
var transportH2 *http2.Transport
transportH2, err = http2.ConfigureTransports(transport)
p.transportH2, err = http2.ConfigureTransports(transport)
if err != nil {
return nil, err
}

// Enable HTTP/2 pings on idle connections.
transportH2.ReadIdleTimeout = transportDefaultReadIdleTimeout
p.transportH2.ReadIdleTimeout = transportDefaultReadIdleTimeout

return transport, nil
}
Expand Down

0 comments on commit f901a5f

Please sign in to comment.