Skip to content

Commit

Permalink
Set MaxIdleConnsPerHost for pushes (#2132)
Browse files Browse the repository at this point in the history
This should reduce "use of closed network connection" errors due to too
many idle connections. Because we only expect to reach a couple hosts
during pushes anyway, this should be safe.

Currently, the value defaults to 2. This change sets it to half the
total IdleConnsPerHost, which defaults to 100.

New value is 100 / 2 = 50.
  • Loading branch information
jonjohnsonjr authored Jul 25, 2022
1 parent 23cd893 commit 55ffa70
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion container/go/cmd/pusher/pusher.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ func push(dst string, img v1.Image) error {
}

httpTransportOption := remote.WithTransport(&headerTransport{
inner: http.DefaultTransport,
inner: newTransport(),
httpHeaders: dockerConfig.HTTPHeaders,
})

Expand Down Expand Up @@ -228,3 +228,13 @@ func (ht *headerTransport) RoundTrip(in *http.Request) (*http.Response, error) {
}
return ht.inner.RoundTrip(in)
}

func newTransport() http.RoundTripper {
tr := http.DefaultTransport.(*http.Transport).Clone()
// We really only expect to be talking to a couple of hosts during a push.
// Increasing MaxIdleConnsPerHost should reduce closed connection errors.
tr.MaxIdleConnsPerHost = tr.MaxIdleConns / 2

return tr
}

0 comments on commit 55ffa70

Please sign in to comment.