Skip to content

Commit 66f189f

Browse files
Merge pull request #134 from thaJeztah/config_idlecons
sockets: ConfigureTransport: prevent idle connections leaking FDs
2 parents 51d157e + dd5901a commit 66f189f

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

sockets/sockets.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,14 @@ var ErrProtocolNotAvailable = errors.New("protocol not available")
2727
// make sure you do it _after_ any subsequent calls to ConfigureTransport is made against the same
2828
// [http.Transport].
2929
func ConfigureTransport(tr *http.Transport, proto, addr string) error {
30+
if tr.MaxIdleConns == 0 {
31+
// prevent long-lived processes from leaking connections
32+
// due to idle connections not being released.
33+
//
34+
// TODO: see if we can also address this from the server side; see: https://github.com/moby/moby/issues/45539
35+
tr.MaxIdleConns = 6
36+
tr.IdleConnTimeout = 30 * time.Second
37+
}
3038
switch proto {
3139
case "unix":
3240
return configureUnixTransport(tr, proto, addr)

0 commit comments

Comments
 (0)