Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HTTPCLIENT-2292: fix regression leading to invalid proxy #512

Closed
wants to merge 1 commit into from
Closed

HTTPCLIENT-2292: fix regression leading to invalid proxy #512

wants to merge 1 commit into from

Conversation

mmoayyed
Copy link

@mmoayyed mmoayyed commented Nov 26, 2023

This seems to have caused a regression in 5.2.2.

java.lang.IllegalArgumentException: Invalid Proxy
    at java.base/java.net.Socket.<init>(Socket.java:216)
    at org.apache.hc.client5.http.ssl.SSLConnectionSocketFactory.createSocket(SSLConnectionSocketFactory.java:208)
    at org.apache.hc.client5.http.impl.io.DefaultHttpClientConnectionOperator.connect(DefaultHttpClientConnectionOperator.java:158)
    at org.apache.hc.client5.http.impl.io.PoolingHttpClientConnectionManager.connect(PoolingHttpClientConnectionManager.java:447)
    at org.apache.hc.client5.http.impl.classic.InternalExecRuntime.connectEndpoint(InternalExecRuntime.java:162)
    at org.apache.hc.client5.http.impl.classic.InternalExecRuntime.connectEndpoint(InternalExecRuntime.java:172) 

When the proxy is undefined or set to null, DefaultHttpClientConnectionOperator does the following:

Timeout soTimeout = socketConfig.getSoTimeout();
SocketAddress socksProxyAddress = socketConfig.getSocksProxyAddress();
Proxy proxy = socksProxyAddress != null ? new Proxy(Type.SOCKS, socksProxyAddress) : null; 

The proxy object above is then null, which means the following call:

Socket sock = sf.createSocket(proxy, context); 

...will eventually pass down to SSLConnectionSocketFactory which does this:

public Socket createSocket(Proxy proxy, HttpContext context) throws IOException {
    return new Socket(proxy); //this proxy cannot be null
} 

I should mention that in the above case,

No SOCKS proxy is ever configured via the PoolingHttpClientConnectionManagerBuilder. setDefaultSocketConfig() method
No SocketConfig.setSocksProxyAddress(socksaddr) exists and is always null.

@mmoayyed mmoayyed changed the base branch from master to 5.2.x November 26, 2023 20:39
@ok2c
Copy link
Member

ok2c commented Nov 26, 2023

Fixed by 6d60624

@ok2c ok2c closed this Nov 26, 2023
@mmoayyed mmoayyed deleted the HTTPCLIENT-2292 branch November 27, 2023 08:32
@mmoayyed
Copy link
Author

Thank you!

@garydgregory
Copy link
Member

garydgregory commented Nov 27, 2023

FWIW, I ran into the same regression. Staying on 5.2.1 for now...
https://issues.apache.org/jira/browse/HTTPCLIENT-2292

@Sineaggi
Copy link

Unfortunately this is still causing issues for projects such as docker-java (see docker-java/docker-java#2290). Currently this bug manifests as a backwards-imcompatible change to projects inheriting from PlainConnectionSocketFactory and SSLConnectionSocketFactory.

I've made an example fix #535 to pull the proxy null check higher out

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.

4 participants