Skip to content

Implement DNS refresh and connection lifetime for HttpClient#16

Merged
kevbite merged 2 commits into
masterfrom
fix/httpclient-stale-dns
May 30, 2026
Merged

Implement DNS refresh and connection lifetime for HttpClient#16
kevbite merged 2 commits into
masterfrom
fix/httpclient-stale-dns

Conversation

@kevbite
Copy link
Copy Markdown
Owner

@kevbite kevbite commented May 30, 2026

This pull request addresses a long-standing issue where the WLedClient(string) constructor could pin a stale DNS entry due to the default HttpClientHandler not refreshing DNS. The changes ensure that the convenience constructor now uses a SocketsHttpHandler with a bounded PooledConnectionLifetime (2 minutes) on modern runtimes, so DNS and IP changes are picked up automatically. The documentation and test suite have also been updated to reflect and verify this improved behavior.

Connection lifetime and DNS refresh improvements:

  • The WLedClient(string) constructor now uses a SocketsHttpHandler with a PooledConnectionLifetime of 2 minutes on supported runtimes, ensuring DNS changes are honored; on netstandard2.0, it falls back to HttpClientHandler. [1] [2]
  • Added a new internal static method CreateDefaultHandler() to encapsulate the handler creation logic and enable testing.

Documentation updates:

  • Updated README.md to explain the new DNS refresh behavior of the WLedClient(string) constructor and reaffirm that IHttpClientFactory/DI remains the recommended approach for applications.
  • Added a changelog entry describing the DNS refresh fix for WLedClient(string).
  • Added a detailed plan document (plans/14-httpclient-connection-lifetime.md) outlining the motivation, approach, and testing strategy for this change; referenced in the plans index. [1] [2]

Testing improvements:

  • Introduced new tests in WLedClientConstructionTests to verify that the string constructor works and, on modern frameworks, that the default handler is a SocketsHttpHandler with the expected connection lifetime.
  • Exposed internals to the test project by adding InternalsVisibleTo in the project file.

#8

kevbite added 2 commits May 30, 2026 18:19
Document the DNS-staleness issue affecting the self-owned HttpClient in
WLedClient(string) and a SocketsHttpHandler PooledConnectionLifetime fix
guarded for the netstandard2.0 target.
Use a SocketsHttpHandler with a 2-minute PooledConnectionLifetime for
the self-owned HttpClient on modern runtimes so a long-lived client
picks up DNS/IP changes, falling back to HttpClientHandler on
netstandard2.0. Expose CreateDefaultHandler internally for testing and
document the behaviour (fixes #8).
@kevbite kevbite self-assigned this May 30, 2026
Copilot AI review requested due to automatic review settings May 30, 2026 17:21
@kevbite kevbite added the enhancement New feature or request label May 30, 2026
@kevbite kevbite merged commit dc76f01 into master May 30, 2026
1 of 2 checks passed
Copy link
Copy Markdown

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.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants