WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

Conversation

@thaJeztah
Copy link
Member

relates to:

Set default MaxIdleConns / IdleConnTimeout to prevent idle connections leaking FDs.

When using the client (initialized via dockercli in my case) in a long-running process, the idle connections are not released. If you create multiple clients the FD count keeps growing indefinitely.

This can be demonstrated against Docker Desktop; other cases have not been tested, but it also depends on the server's behavior and when the server will drop the connections.

Other possible fixes could be:

  • initialize transport from DefaultTransport (that has better defaults)
  • Somehow wrap transport so all clients use the same keepalive pool
  • Make this configurable. I would also need dockerCLI update then.
  • Explore server side
  • There is a call to CloseIdleConns but that lifecycle is tricky to manage when initializing clients via dockerCLI based on multiple configs. Possibly defining a Finalizer could also result in the desired behavior.

This patch migrates the code from moby@5c72a95 to this module.

- Description for the changelog

sockets: ConfigureTransport: prevent idle connections leaking FDs

- A picture of a cute animal (not mandatory but encouraged)

@thaJeztah thaJeztah requested a review from Copilot July 1, 2025 09:27
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR sets default values for MaxIdleConns and IdleConnTimeout in the HTTP transport to prevent file descriptor leaks when idle connections persist in long-lived processes.

  • Set default MaxIdleConns to 6 if not already set.
  • Set IdleConnTimeout to 30 seconds to ensure idle connections are released.

// due to idle connections not being released.
//
// TODO: see if we can also address this from the server side; see: https://github.com/moby/moby/issues/45539
tr.MaxIdleConns = 6
Copy link

Copilot AI Jul 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Consider extracting the magic number '6' into a named constant for improved clarity and maintainability.

Suggested change
tr.MaxIdleConns = 6
tr.MaxIdleConns = defaultMaxIdleConns

Copilot uses AI. Check for mistakes.
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll keep this for now; keeping all of these together may more clearly indicate the slightly "ad-hoc" nature of this.

//
// TODO: see if we can also address this from the server side; see: https://github.com/moby/moby/issues/45539
tr.MaxIdleConns = 6
tr.IdleConnTimeout = 30 * time.Second
Copy link

Copilot AI Jul 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Consider extracting the timeout value '30 * time.Second' into a named constant to allow for easier configuration and clearer intent.

Suggested change
tr.IdleConnTimeout = 30 * time.Second
tr.IdleConnTimeout = idleConnTimeout

Copilot uses AI. Check for mistakes.
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll keep this for now; keeping all of these together may more clearly indicate the slightly "ad-hoc" nature of this.

Set default `MaxIdleConns` / `IdleConnTimeout` to prevent idle connections
leaking FDs.

When using the client (initialized via `dockercli` in my case) in a
long-running process, the idle connections are not released. If you
create multiple clients the FD count keeps growing indefinitely.

This can be demonstrated against Docker Desktop; other cases have not
been tested, but it also depends on the server's behavior and when the
server will drop the connections.

Other possible fixes could be:

- initialize transport from DefaultTransport (that has better defaults)
- Somehow wrap transport so all clients use the same keepalive pool
- Make this configurable. I would also need dockerCLI update then.
- Explore server side
- There is a call to `CloseIdleConns` but that lifecycle is tricky to
  manage when initializing clients via `dockerCLI` based on multiple
  configs. Possibly defining a `Finalizer` could also result in the
  desired behavior.

This patch migrates the code from [moby@5c72a95] to this module.

[moby@5c72a95]: moby/moby@5c72a95

Signed-off-by: Sebastiaan van Stijn <[email protected]>
@thaJeztah
Copy link
Member Author

/cc @austinvazquez - looks like I forgot about this one; mostly so that we can remove the same patch from moby

(that said, we should probably look at removing most of this package, and have it as part of moby)

Copy link
Contributor

@austinvazquez austinvazquez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍🏼

@austinvazquez austinvazquez merged commit 66f189f into docker:main Aug 8, 2025
13 checks passed
@thaJeztah thaJeztah deleted the config_idlecons branch August 8, 2025 15:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants