Skip to content

Conversation

@oliviamariacodes
Copy link
Contributor

@oliviamariacodes oliviamariacodes commented Oct 24, 2025

Fixes #12444

This PR addresses a bug in the NameResolver.Listener to NameResolver.Listener2 bridge affecting custom NameResolver implementations using Listener.

The bridge in NameResolver.start(Listener) at https://github.com/grpc/grpc-java/blob/master/api/src/main/java/io/grpc/NameResolver.java#L100 unconditionally calls getValue() on the StatusOr, throwing java.lang.IllegalStateException: No value present. when the result contains an error.

This was identified when upgrading from gRPC v1.63.3 to v1.75.0.

The bug occurs due to DnsNameResolver's error handling changes between versions:

This PR updates the bridge to check whether ResolutionResult contains addresses or an error. It passes the error via onError and addresses via onAddresses.

Reproducing the Issue
The startOnOldListener_resolverReportsError test reproduces a similar issue. It creates a custom NameResolver that reports errors through the ResolutionResult like the DNSNameResolver in v1.75.0, passes an old Listener to resolver.start, which triggers the bridge code path.

Without the fix, the bridge calls getValue() on the error containing StatusOr, throwing IllegalStateException: No value present.

With the fix, the bridge checks hasValue() first and correctly routes to listener.onError() when appropriate. This ensures backward compatibility for Listener implementations when resolvers report errors via ResolutionResult.

@linux-foundation-easycla
Copy link

linux-foundation-easycla bot commented Oct 24, 2025

CLA Signed

The committers listed above are authorized under a signed CLA.

@oliviamariacodes oliviamariacodes changed the title Name Resolver Listener Bug Fix Fix name resolver bridge listener handling Oct 24, 2025
@oliviamariacodes oliviamariacodes marked this pull request as ready for review October 24, 2025 22:49
@kannanjgithub kannanjgithub self-requested a review October 28, 2025 07:26
@kannanjgithub kannanjgithub added the kokoro:run Add this label to a PR to tell Kokoro the code is safe and tests can be run label Oct 28, 2025
@grpc-kokoro grpc-kokoro removed the kokoro:run Add this label to a PR to tell Kokoro the code is safe and tests can be run label Oct 28, 2025
@kannanjgithub
Copy link
Contributor

@oliviamariacodes please sign the Easy CLA agreement before being able to contribute to the repo.

@kannanjgithub kannanjgithub added the kokoro:run Add this label to a PR to tell Kokoro the code is safe and tests can be run label Oct 29, 2025
@grpc-kokoro grpc-kokoro removed the kokoro:run Add this label to a PR to tell Kokoro the code is safe and tests can be run label Oct 29, 2025
@kannanjgithub kannanjgithub merged commit acbbf86 into grpc:master Oct 29, 2025
21 of 23 checks passed
AgraVator pushed a commit to AgraVator/grpc-java that referenced this pull request Nov 3, 2025
…n errors (grpc#12441)

Fixes grpc#12444

This PR addresses a bug in the `NameResolver.Listener` to
`NameResolver.Listener2` bridge affecting custom NameResolver
implementations using Listener.

The bridge in `NameResolver.start(Listener)` at
https://github.com/grpc/grpc-java/blob/master/api/src/main/java/io/grpc/NameResolver.java#L100
unconditionally calls `getValue()` on the `StatusOr`, throwing
`java.lang.IllegalStateException: No value present.` when the result
contains an error.

This was identified when upgrading from gRPC `v1.63.3` to `v1.75.0`. 

The bug occurs due to `DnsNameResolver`'s error handling changes between
versions:

- `v1.63.3`: Errors reported via `Listener.onError()`
(https://github.com/grpc/grpc-java/blob/v1.63.x/core/src/main/java/io/grpc/internal/DnsNameResolver.java#L319)
- `v1.75.0`: Errors passed via `Listener2.onResult2()` with a
ResolutionResult containing either addresses OR an error
(https://github.com/grpc/grpc-java/blob/master/core/src/main/java/io/grpc/internal/DnsNameResolver.java#L322)

This PR updates the bridge to check whether `ResolutionResult` contains
addresses or an error. It passes the error via `onError` and addresses
via `onAddresses`.

**Reproducing the Issue**
The `startOnOldListener_resolverReportsError` test reproduces a similar
issue. It creates a custom `NameResolver` that reports errors through
the `ResolutionResult` like the `DNSNameResolver` in `v1.75.0`, passes
an old Listener to `resolver.start`, which triggers the bridge code
path.

Without the fix, the bridge calls `getValue()` on the error containing
`StatusOr`, throwing `IllegalStateException: No value present`.

With the fix, the bridge checks `hasValue()` first and correctly routes
to `listener.onError()` when appropriate. This ensures backward
compatibility for `Listener` implementations when resolvers report
errors via `ResolutionResult`.
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.

Name Resolver Bridge Listener Handling

3 participants