Commit acbbf86
authored
api: Fix name resolver bridge listener handling for address resolution errors (#12441)
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:
- `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`.1 parent 9b424b3 commit acbbf86
File tree
2 files changed
+58
-2
lines changed- api/src
- main/java/io/grpc
- test/java/io/grpc
2 files changed
+58
-2
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
97 | 97 | | |
98 | 98 | | |
99 | 99 | | |
100 | | - | |
101 | | - | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
102 | 108 | | |
103 | 109 | | |
104 | 110 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
192 | 192 | | |
193 | 193 | | |
194 | 194 | | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
195 | 245 | | |
196 | 246 | | |
197 | 247 | | |
| |||
0 commit comments