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

[iptables -j REJECT/DROP][java.net.SocketException: Connection reset] Q:How to handle these exceptions? #234

Open
freedom1b2830 opened this issue Oct 11, 2022 · 9 comments

Comments

@freedom1b2830
Copy link

The situation is this, some ip addresses are blocked by iptables (iptables -A OUTPUT -d ip -j REJECT). Because of this, the proxy gives these exceptions:

окт. 11, 2022 12:43:15 PM io.netty.channel.AbstractChannelHandlerContext invokeExceptionCaught
WARNING: An exception 'java.lang.NullPointerException: Cannot invoke "com.github.monkeywie.proxyee.handler.HttpProxyServerHandler.getExceptionHandle()" because the return value of "io.netty.channel.ChannelPipeline.get(String)" is null' [enable DEBUG level for full stacktrace] was thrown by a user handler's exceptionCaught() method while handling the following exception:
java.net.SocketException: Connection reset
	at java.base/sun.nio.ch.SocketChannelImpl.throwConnectionReset(SocketChannelImpl.java:394)
	at java.base/sun.nio.ch.SocketChannelImpl.read(SocketChannelImpl.java:426)
	at io.netty.buffer.PooledByteBuf.setBytes(PooledByteBuf.java:258)
	at io.netty.buffer.AbstractByteBuf.writeBytes(AbstractByteBuf.java:1132)
	at io.netty.channel.socket.nio.NioSocketChannel.doReadBytes(NioSocketChannel.java:357)
	at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:151)
	at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:722)
	at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:658)
	at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:584)
	at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:496)
	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)

How to assign a handler for these exceptions/silence these exceptions?

@freedom1b2830
Copy link
Author

also how to do it?
"enable DEBUG level for full stacktrace"

@freedom1b2830 freedom1b2830 changed the title How to handle these exceptions? How to handle these exceptions? [iptables -j REJECT/DROP] Oct 11, 2022
@freedom1b2830 freedom1b2830 changed the title How to handle these exceptions? [iptables -j REJECT/DROP] [iptables -j REJECT/DROP][java.net.SocketException: Connection reset] Q:How to handle these exceptions? Oct 11, 2022
@monkeyWie
Copy link
Owner

monkeyWie commented Oct 12, 2022

can you post code?

@monkeyWie
Copy link
Owner

Unable to reproduce, can you provide the simplest and reproducible code?

@freedom1b2830
Copy link
Author

freedom1b2830 commented Oct 13, 2022

@monkeyWie
Copy link
Owner

@freedom1b2830 Pls provide specific reproduction steps, such as:

1. xxx
2. xxx
3. curl -k -x 127.0.0.1:9999 https://www.google.com

@freedom1b2830
Copy link
Author

1.generated a root certificate
2.added it to the trusted centers in the systems (trust anchor –store /path)
3.configured firefox (http+https proxy)
4.I visited sites where there are resources from blocked domains through iptables (iptables -A OUTPUT -d $blockedIP -j REJECT)

@monkeyWie
Copy link
Owner

@freedom1b2830 I still can't reproduce the problem, can you test with curl command?
My test:

1. add a line of code `domainsBlockRegEx.add("baidu.com")` 
2. ping www.badu.com get ip 14.215.177.39
3. sudo iptables -A OUTPUT -d 14.215.177.39 -j REJECT
4. start server
5. curl -k -x 127.0.0.1:9999 https://www.baidu.com

and it no exception.
image

@freedom1b2830
Copy link
Author

freedom1b2830 commented Oct 19, 2022

the application was suspended at the time of the NPE being thrown out

heap dump
1.zip

in code:

@Override
    public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
        ctx.channel().close();
        clientChannel.close();
        HttpProxyExceptionHandle exceptionHandle = ((HttpProxyServerHandler) clientChannel.pipeline()
                .get("serverHandle")).getExceptionHandle();
        exceptionHandle.afterCatch(clientChannel, ctx.channel(), cause);
    }

(HttpProxyServerHandler) clientChannel.pipeline().get("serverHandle")==null

I am getting an exception in this thread

"nioEventLoopGroup-2-4" #38 prio=10 os_prio=0 cpu=397,75ms elapsed=199,42s tid=0x00007f284c083b70 nid=107057 runnable  [0x00007f2839df6000]
   java.lang.Thread.State: RUNNABLE
	at com.github.monkeywie.proxyee.handler.HttpProxyClientHandler.exceptionCaught(HttpProxyClientHandler.java:55)
	at io.netty.channel.AbstractChannelHandlerContext.invokeExceptionCaught(AbstractChannelHandlerContext.java:302)
	at io.netty.channel.AbstractChannelHandlerContext.invokeExceptionCaught(AbstractChannelHandlerContext.java:281)
	at io.netty.channel.AbstractChannelHandlerContext.fireExceptionCaught(AbstractChannelHandlerContext.java:273)
	at io.netty.channel.CombinedChannelDuplexHandler$DelegatingChannelHandlerContext.fireExceptionCaught(CombinedChannelDuplexHandler.java:424)
	at io.netty.channel.ChannelHandlerAdapter.exceptionCaught(ChannelHandlerAdapter.java:92)
	at io.netty.channel.CombinedChannelDuplexHandler$1.fireExceptionCaught(CombinedChannelDuplexHandler.java:145)
	at io.netty.channel.ChannelInboundHandlerAdapter.exceptionCaught(ChannelInboundHandlerAdapter.java:143)
	at io.netty.channel.CombinedChannelDuplexHandler.exceptionCaught(CombinedChannelDuplexHandler.java:231)
	at io.netty.channel.AbstractChannelHandlerContext.invokeExceptionCaught(AbstractChannelHandlerContext.java:302)
	at io.netty.channel.AbstractChannelHandlerContext.invokeExceptionCaught(AbstractChannelHandlerContext.java:281)
	at io.netty.channel.AbstractChannelHandlerContext.fireExceptionCaught(AbstractChannelHandlerContext.java:273)
	at io.netty.handler.ssl.SslHandler.exceptionCaught(SslHandler.java:1105)
	at io.netty.channel.AbstractChannelHandlerContext.invokeExceptionCaught(AbstractChannelHandlerContext.java:302)
	at io.netty.channel.AbstractChannelHandlerContext.invokeExceptionCaught(AbstractChannelHandlerContext.java:281)
	at io.netty.channel.AbstractChannelHandlerContext.fireExceptionCaught(AbstractChannelHandlerContext.java:273)
	at io.netty.channel.DefaultChannelPipeline$HeadContext.exceptionCaught(DefaultChannelPipeline.java:1377)
	at io.netty.channel.AbstractChannelHandlerContext.invokeExceptionCaught(AbstractChannelHandlerContext.java:302)
	at io.netty.channel.AbstractChannelHandlerContext.invokeExceptionCaught(AbstractChannelHandlerContext.java:281)
	at io.netty.channel.DefaultChannelPipeline.fireExceptionCaught(DefaultChannelPipeline.java:907)
	at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.handleReadException(AbstractNioByteChannel.java:125)
	at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:177)
	at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:722)
	at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:658)
	at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:584)
	at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:496)
	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.lang.Thread.run(java.base@18.0.2/Thread.java:833)

   Locked ownable synchronizers:
	- None

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

No branches or pull requests

2 participants