Android: ProxyDetectorImpl crashes when DefaultProxySelector contains an invalid proxy port
I maintainer di solito rispondono entro 2 giorni
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 2/5
- Tempo stimato
- 1-3 ore
- Idoneità per principianti
- 78/100
- Tipo di issue
- Bug
- Chiarezza
- Specificata chiaramente
- Stato di attività
- Attiva
- Ambito
- backend-api-design, networking
Direzione di ricerca
Inizia in core/src/main/java/io/grpc/internal/ProxyDetectorImpl.java intorno a detectProxy e alle righe identificate dall’ispezione del codice sorgente, quindi segui il modo in cui DnsNameResolver lo invoca. Riproduci il caso con un https.proxyPort fuori intervallo e attiva la risoluzione dei nomi. Il lavoro è completato quando una IllegalArgumentException da ProxySelector.select() non causa più il crash del resolver e uno stato del proxy non valido ripiega sulla connettività diretta.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
What version of gRPC-Java are you using?
1.66.0
Source inspection indicates that latest 1.84.0 is also affected.
What is your environment?
Android production application.
Most events are from Android 13 devices (89%), predominantly Xiaomi (85%).
What did you expect to see?
A malformed system proxy configuration should not cause an uncaught exception on the gRPC resolver executor.
Because the configured proxy cannot be used, gRPC should preferably treat it as no usable proxy and continue with a direct connection. At minimum, it should convert the exception into an ordinary name-resolution failure instead of terminating the process.
What did you see instead?
Android’s DefaultProxySelector throws IllegalArgumentException while constructing a proxy address with an out-of-range port. The exception escapes through ProxyDetectorImpl and becomes a fatal process crash.
Fatal Exception: java.lang.IllegalArgumentException: port out of range:899858473
at java.net.InetSocketAddress.checkPort(InetSocketAddress.java:154)
at java.net.InetSocketAddress.createUnresolved(InetSocketAddress.java:279)
at sun.net.spi.DefaultProxySelector$1.run(DefaultProxySelector.java:315)
at sun.net.spi.DefaultProxySelector$1.run(DefaultProxySelector.java:219)
at java.security.AccessController.doPrivileged(AccessController.java:46)
at sun.net.spi.DefaultProxySelector.select(DefaultProxySelector.java:218)
at io.grpc.internal.ProxyDetectorImpl.detectProxy(ProxyDetectorImpl.java:230)
at io.grpc.internal.ProxyDetectorImpl.proxyFor(ProxyDetectorImpl.java:200)
at io.grpc.internal.DnsNameResolver.detectProxy(DnsNameResolver.java:269)
at io.grpc.internal.DnsNameResolver.access$600(DnsNameResolver.java:66)
at io.grpc.internal.DnsNameResolver$Resolve.run(DnsNameResolver.java:310)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1100)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:1572)
We observed multiple affected devices with different invalid ports. Each invalid value remains stable for its affected device. This suggests malformed device/system proxy state rather than corruption inside gRPC.
Analysis
On Android 13, DefaultProxySelector.select() reads the process proxy properties and passes the configured port directly to InetSocketAddress.createUnresolved().
InetSocketAddress rejects ports outside 0..65535.
The invalid value is the system proxy port, not the gRPC destination port. Although gRPC does not produce the malformed configuration, ProxyDetectorImpl currently allows the platform exception to escape from the resolver task.
The existing handling for a ProxySelector returning null or an empty list does not cover this case because the exception is thrown inside ProxySelector.select().
Comparable OkHttp behavior
OkHttp’s current implementation handles this exact case by catching IllegalArgumentException from ProxySelector.select() and treating it as no usable proxy, falling back to Proxy.NO_PROXY.
Its source explicitly explains the reason:
// A misconfigured system proxy (such as one with no port set) can make
// ProxySelector.select() itself throw IllegalArgumentException; treat that
// as "no usable proxy" rather than letting it crash.
Applying equivalent handling in gRPC would provide consistent behavior between regular OkHttp traffic and the gRPC OkHttp transport.
Reproduction
We have not reproduced the original malformed Android proxy state locally.
A synthetic reproduction should be possible by configuring:
https.proxyHost=<non-empty host>
https.proxyPort=<integer greater than 65535>
and then triggering name resolution through a gRPC channel using the default proxy detector.
Suggested change
Catch IllegalArgumentException around ProxySelector.select() and treat the result as no proxy:
final List<Proxy> proxies;
try {
proxies = proxySelector.select(uri);
} catch (IllegalArgumentException e) {
log.log(
Level.WARNING,
"ProxySelector failed while selecting a proxy; proceeding without proxy",
e);
return null;
}
Returning null from ProxyDetectorImpl.detectProxy() preserves connectivity through a direct connection and matches OkHttp’s behavior for malformed system proxy configuration.
If silently falling back to direct connectivity is considered inappropriate, converting the exception to IOException would still prevent a fatal process crash, although the channel would remain unavailable while the malformed proxy configuration persists.
- Lingua principale
- Java
- Stelle
- 12.1k
- Fork
- 4k
- Merge medio
- 2g 3h
- PR unite (30g)
- 30
Preparare l'ambiente
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di grpc/grpc-java
-
enhancement
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100
I maintainer di solito rispondono entro 2 giorni
-
Support of `dns:name` URIsApertadocs enhancement
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
grpc/grpc-java#10824 · 8 commenti ·
I maintainer di solito rispondono entro 2 giorni
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 70/100
I maintainer di solito rispondono entro 2 giorni
-
Difficoltà 3/5 1-2 giorni Idoneità per principianti 65/100
I maintainer di solito rispondono entro 2 giorni
-
enhancement
Difficoltà 4/5 3-5 giorni Idoneità per principianti 30/100
I maintainer di solito rispondono entro 2 giorni
Tutte le issue di grpc/grpc-java
Issue simili
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
openhab/openhab-core#5847 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100
apache/parquet-java#3820 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
beehive-lab/jllm#187 ·