Exception `java.util.NoSuchElementException: socks` when making https request with socks5 proxy
Fallen-Breath opened this issue ยท 6 comments
Fallen-Breath commented
To reproduce
package me.fallenbreath.playground;
import org.asynchttpclient.proxy.ProxyType;
import static org.asynchttpclient.Dsl.*;
public class Main
{
public static void main(String[] args) throws Exception
{
var proxyServer = proxyServer("127.0.0.1", 1081).
setProxyType(ProxyType.SOCKS_V5);
try (var client = asyncHttpClient(config().setProxyServer(proxyServer)))
{
var response = client.prepareGet("https://cloudflare.com/cdn-cgi/trace").execute().get();
System.out.println(response);
}
}
}Exception:
Exception in thread "main" java.util.concurrent.ExecutionException: java.net.ConnectException: socks
at java.base/java.util.concurrent.CompletableFuture.reportGet(CompletableFuture.java:396)
at java.base/java.util.concurrent.CompletableFuture.get(CompletableFuture.java:2073)
at org.asynchttpclient.netty.NettyResponseFuture.get(NettyResponseFuture.java:210)
at me.fallenbreath.playground.Main.main(Main.java:16)
Caused by: java.net.ConnectException: socks
at org.asynchttpclient.netty.channel.NettyConnectListener.onFailure(NettyConnectListener.java:173)
at org.asynchttpclient.netty.channel.NettyConnectListener.onSuccess(NettyConnectListener.java:109)
at org.asynchttpclient.netty.channel.NettyChannelConnector$1.onSuccess(NettyChannelConnector.java:91)
at org.asynchttpclient.netty.SimpleChannelFutureListener.operationComplete(SimpleChannelFutureListener.java:28)
at org.asynchttpclient.netty.SimpleChannelFutureListener.operationComplete(SimpleChannelFutureListener.java:22)
at io.netty.util.concurrent.DefaultPromise.notifyListener0(DefaultPromise.java:590)
at io.netty.util.concurrent.DefaultPromise.notifyListeners0(DefaultPromise.java:583)
at io.netty.util.concurrent.DefaultPromise.notifyListenersNow(DefaultPromise.java:559)
at io.netty.util.concurrent.DefaultPromise.notifyListeners(DefaultPromise.java:492)
at io.netty.util.concurrent.DefaultPromise.setValue0(DefaultPromise.java:636)
at io.netty.util.concurrent.DefaultPromise.setSuccess0(DefaultPromise.java:625)
at io.netty.util.concurrent.DefaultPromise.trySuccess(DefaultPromise.java:105)
at io.netty.channel.DefaultChannelPromise.trySuccess(DefaultChannelPromise.java:84)
at io.netty.channel.nio.AbstractNioChannel$AbstractNioUnsafe.fulfillConnectPromise(AbstractNioChannel.java:300)
at io.netty.channel.nio.AbstractNioChannel$AbstractNioUnsafe.finishConnect(AbstractNioChannel.java:335)
at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:776)
at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:724)
at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:650)
at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:562)
at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:997)
at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74)
at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
at java.base/java.lang.Thread.run(Thread.java:833)
Caused by: java.util.NoSuchElementException: socks
at io.netty.channel.DefaultChannelPipeline.getContextOrDie(DefaultChannelPipeline.java:1073)
at io.netty.channel.DefaultChannelPipeline.addAfter(DefaultChannelPipeline.java:302)
at io.netty.channel.DefaultChannelPipeline.addAfter(DefaultChannelPipeline.java:290)
at org.asynchttpclient.netty.channel.ChannelManager.addSslHandler(ChannelManager.java:427)
at org.asynchttpclient.netty.channel.NettyConnectListener.onSuccess(NettyConnectListener.java:107)
... 21 more
The issue only occurs with socks5 + https. Sock4 is not tested, and http proxy works normally
Environment:
- Java 11
org.asynchttpclient:async-http-client:3.0.0.Beta2
lakxtxue commented
I have the same problem.
cuicuicuinice commented
้พ้กถ๏ผๆไน้ๅฐไบ...
010227leo commented
the same problem, do you have any solutions? @hyperxpro
hyperxpro commented
the same problem, do you have any solutions? @hyperxpro
Unfortunately no. But feel free to raise a PR. :)
leandroutn commented
I think netty/netty#11945 is the cause of the issue
If I force the use of netty-transport 4.1.72.Final => I cannot reproduce this anymore
api ('io.netty:netty-transport') { version { strictly '4.1.72.Final' } }
I've debugged it and !ctx.isRemoved() does not behave the same as pipeline.context(this) != null, leading initChannel to drop it
I actually use this to verify the change in behavior
@Test public void testSSL() throws ExecutionException, InterruptedException, IOException { AsyncHttpClientConfig config = new DefaultAsyncHttpClientConfig.Builder() .setProxyServerSelector(uri -> new ProxyServer.Builder("<your_proxy>", 1080) .setProxyType(ProxyType.SOCKS_V5) .build()) .build(); try (AsyncHttpClient asyncHttpClient = new DefaultAsyncHttpClient(config)) { int code = asyncHttpClient.prepare("GET", "https://example.org/") .execute() .get() .getStatusCode(); assertEquals(200, code); } }
I've opened netty/netty#14679