Implement DNS refresh and connection lifetime for HttpClient#16
Merged
Conversation
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).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This pull request addresses a long-standing issue where the
WLedClient(string)constructor could pin a stale DNS entry due to the defaultHttpClientHandlernot refreshing DNS. The changes ensure that the convenience constructor now uses aSocketsHttpHandlerwith a boundedPooledConnectionLifetime(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:
WLedClient(string)constructor now uses aSocketsHttpHandlerwith aPooledConnectionLifetimeof 2 minutes on supported runtimes, ensuring DNS changes are honored; onnetstandard2.0, it falls back toHttpClientHandler. [1] [2]CreateDefaultHandler()to encapsulate the handler creation logic and enable testing.Documentation updates:
README.mdto explain the new DNS refresh behavior of theWLedClient(string)constructor and reaffirm thatIHttpClientFactory/DI remains the recommended approach for applications.WLedClient(string).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:
WLedClientConstructionTeststo verify that the string constructor works and, on modern frameworks, that the default handler is aSocketsHttpHandlerwith the expected connection lifetime.InternalsVisibleToin the project file.#8