Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

Android: ProxyDetectorImpl crashes when DefaultProxySelector contains an invalid proxy port

未关闭 适合新手
#13,052 4 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 2 天内回复

还没有人认领这个 Issue。

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
78/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
android, java

调研方向

从 core/src/main/java/io/grpc/internal/ProxyDetectorImpl.java 中的 detectProxy 附近以及源代码检查所识别的行开始,然后跟踪 DnsNameResolver 如何调用它。使用超出范围的 https.proxyPort 重现该情况,并触发名称解析。当 ProxySelector.select() 抛出的 IllegalArgumentException 不再导致 resolver 崩溃,并且格式错误的代理状态回退到直接连接时,即表示完成。

由索引模型根据 Issue 内容生成。

描述

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.

主要语言
Java
星标
12.1k
派生
4k
平均合并
2 天 3 小时
30 天内合并 PR
30

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

grpc/grpc-java 的其他 Issue

查看 grpc/grpc-java 的全部 Issue

相似的 Issue

更多 Java Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。