Skip to content

Deprecate ambiguous IPv4 and IPv6 target APIs #117

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jul 14, 2025
Merged

Conversation

glbrntt
Copy link
Collaborator

@glbrntt glbrntt commented Jul 14, 2025

Motivation:

The API for creating IPv4/IPv6 resolvable targets is a bit ambiguous: it's quite easy to assume they will only resolve IPv4 or IPv6 addresses. Instead they expect to be provided with resolved IPv4 or IPv6 addresses.

Modifications:

  • Deprecate these APIs and replace them with more obvious spellings
  • Add a debug-only check to validate that the target is a valid IPv4/IPv6 address

Result:

  • Harder to make mistakes
  • Easier to diagnose mistakes

Motivation:

The API for creating IPv4/IPv6 resolvable targets is a bit ambiguous:
it's quite easy to assume they will only resolve IPv4 or IPv6 addresses.
Instead they expect to be provided with resolved IPv4 or IPv6 addresses.

Modifications:

- Deprecate these APIs and replace them with more obvious spellings
- Add a debug-only check to validate that the target is a valid
  IPv4/IPv6 address

Result:

- Harder to make mistakes
- Easier to diagnose mistakes
@@ -29,6 +30,23 @@ extension ResolvableTargets {
/// Create a new IPv6 target.
/// - Parameter addresses: The IPv6 addresses.
public init(addresses: [SocketAddress.IPv6]) {
debugOnly {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Wouldn't it also be useful to get some better error other than the current unavailable: "Channel isn't ready." in release builds, too?

I'm thinking if the address comes from some config and there are different values for debug and release, it's possible that debug builds won't fail but then you'd get some confusing error in release.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It would be useful but at that layer you don't have enough information to tie it back to creating the wrong resolver. The "Channel isn't ready." message can happen for any number of reasons, including you could've correctly used a resolver but the server just isn't up yet.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I guess my question was actually if we should always perform this check, not just in debug mode (throwing an error instead of failing an assertion), or if it's too expensive to afford it in this codepath.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I don't think it's necessary tbh, the change in spelling is clear enough.

@glbrntt glbrntt merged commit 9e2bab9 into grpc:main Jul 14, 2025
29 checks passed
@glbrntt glbrntt deleted the rename branch July 14, 2025 17:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🆕 semver/minor Adds new public API.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants