Skip to content

Don't crash route selection when the system proxy selector throws#9478

Open
SAY-5 wants to merge 1 commit into
square:masterfrom
SAY-5:fix-proxyselector-iae
Open

Don't crash route selection when the system proxy selector throws#9478
SAY-5 wants to merge 1 commit into
square:masterfrom
SAY-5:fix-proxyselector-iae

Conversation

@SAY-5
Copy link
Copy Markdown

@SAY-5 SAY-5 commented Jun 6, 2026

Fixes #9469.

When no explicit proxy is configured, RouteSelector calls address.proxySelector.select(uri) and only handles a null/empty return. On Android the platform DefaultProxySelector can itself throw IllegalArgumentException: port out of range:-1 when a system proxy is configured (via APN/MDM) with an unset port. That exception propagates out of resetNextProxy and crashes the call on the dispatcher thread, even though OkHttp already rejects out-of-range proxy ports elsewhere.

This treats a throwing ProxySelector.select() the same as a null/empty result and falls back to a direct connection, which matches how the surrounding code already handles "no usable proxy". Added a RouteSelectorTest case that fails on the current code and passes with the fix.

Signed-off-by: Sai Asish Y <say.apm35@gmail.com>
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.

IllegalArgumentException: port out of range:-1 from DefaultProxySelector.select() propagates uncaught through RouteSelector.resetNextProxy

1 participant