core: Handle ProxySelector IllegalArgumentException - #13053
kkmurthyt21 wants to merge 1 commit into
Conversation
|
|
|
Thanks for picking this up. Approach is right, a few things need changing. The test doesn't cover the actual bug. Related: Also worth knowing: the message you're building never reaches the user, because |
| IOException exception = | ||
| assertThrows(IOException.class, () -> proxyDetector.proxyFor(destination)); | ||
|
|
||
| assertEquals(cause, exception.getCause()); |
There was a problem hiding this comment.
Nit: assertSame for the cause.
There was a problem hiding this comment.
Thanks for taking a close look. This is helpful. I agree that a resolver level test would better cover the actual failure path, and I will change the cause check to assertSame.
Before I rework the implementation, could one of the maintainers confirm the preferred behavior? Should this fall back to a direct connection, or return UNAVAILABLE? Also, should the broader RuntimeException handling be placed around detectProxy() in DnsNameResolver?
Once that is confirmed, I will update the implementation.
Fixes #13052.
Android’s
DefaultProxySelector.select()may throwIllegalArgumentExceptionwhen the system proxy configuration contains an invalid port. This unchecked exception currently escapes the DNS resolver task and can terminate the process.This change catches the exception at the
ProxySelector.select()call and wraps it in anIOException. The original cause is preserved, and the exception message identifies theProxySelectorimplementation.DnsNameResolveralready handles anIOExceptionfrom proxy detection as anUNAVAILABLEname-resolution result. This allows the resolver to fail cleanly instead of letting the unchecked exception escape.This intentionally avoids silently falling back to a direct connection. It follows the fail-cleanly approach used for invalid
ProxySelectorresults in #12793 and avoids bypassing a configured proxy.Testing
ProxySelectorimplementation is identified..\gradlew.bat :grpc-core:test --tests "io.grpc.internal.ProxyDetectorImplTest"