Type: Feature client: Add WithTargetCheck DialOption for early target validation #8743
+145
−0
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.
Fixes #8739
Motivation
When migrating from the deprecated
grpc.DialwithWithBlock()andWithTimeout()togrpc.NewClient,there is no built-in way to validate target reachability during client initialization without blocking behavior. This PR introducesWithTargetCheckas an alternative that validates DNS resolution and TCP reachability without the complexity and anti-patterns associated withWithBlock().Use Case
This option is valuable for scenarios where:
Unlike
WithBlock(),WithTargetCheckperforms a single validation check during NewClient() and does not interfere with the connection lifecycle or background reconnection logic.Implementation
This PR adds:
New DialOption:WithTargetCheck(timeout time.Duration)- performs DNS resolution and TCP dial validation for "dns" and "passthrough" schemesValidation logic: AddedvalidateTargetmethod toClientConnthat attempts a TCP connection within the specified timeoutTests: unit tests covering success and failure casesThe implementation:
NewClient()initializationRELEASE NOTES:
client: Added
WithTargetCheckDialOption to validate target DNS resolution and TCP reachability during client initialization, providing a lightweight alternative to deprecated WithBlock() for fail-fast scenarios.