core: handle empty proxy selector result#12793
Conversation
|
|
da37275 to
ac43fae
Compare
|
Hi @ejona86, would you be the right person to review this small proxy detection fix? |
|
Can we identify the broken Android deployments? I know we can't fix them, but we can document what software we are working around. The Java API says there will always be entries in the list, so both null and empty list are invalid. I'd normally suggest we fail (cleanly, not like it is now) instead of ignoring the API breakage. |
Thanks for the context. |
|
So I've looked around some, and I don't see any other reports of something like this. I'm very suspicious, as Android 14 is plenty old enough for us to have heard of this problem. It is seeming more likely at this point that maybe you have a broken ProxySelector configured somewhere in your app. How does this sound: Add in checks for null/isEmpty(), and throw an IOException with the classname of the ProxySelector as part of the error string. I know exception strings are often discarded on Android, but this has no semantic concerns and would help anyone that accidentally writes a broken ProxySelector. Ideally the ProxySelector would get fixed, instead of all callers working around it. If we find out this behavior is widespread we would re-evaluate the approach. |
|
@mfperminov are you planning to add the debug info suggested? |
Yes, I’ll add the suggested debug info today. |
ac43fae to
05ead32
Compare
ProxySelector.select(URI) is contractually required to return a non-null,
non-empty list. Some implementations violate this, which previously caused
an opaque crash in ProxyDetectorImpl:
java.lang.IndexOutOfBoundsException: Index: 0
at java.util.Collections$EmptyList.get
at io.grpc.internal.ProxyDetectorImpl.detectProxy
Detect this case explicitly and throw an IOException naming the offending
ProxySelector class, so a broken implementation can be identified and
fixed by its author rather than silently worked around in every caller.
05ead32 to
b76589c
Compare
|
@ejona86 @kannanjgithub |
|
/gcbrun |
Fixes a crash in
ProxyDetectorImplwhenProxySelector.select(URI)returns an empty list.On some Android devices/configurations,
ProxySelector.select(uri)can returnCollections.emptyList().ProxyDetectorImplpreviously assumed the returned listalways contained at least one element and called proxies.get(0), causing:
This change treats null/empty proxy selector results as "no proxy" and proceeds
without proxy, matching the behavior for
Proxy.Type.DIRECT.Added a unit test covering an empty proxy list.