From 57d1af5427c25e069bbb95b450939bff6c64fcc1 Mon Sep 17 00:00:00 2001 From: RaphiMC <50594595+RaphiMC@users.noreply.github.com> Date: Fri, 19 Jul 2024 15:31:22 +0200 Subject: [PATCH] Fixed proxy connect race condition --- .../viaproxy/proxy/client2proxy/Client2ProxyHandler.java | 5 ++--- .../java/net/raphimc/viaproxy/proxy/util/ExceptionUtil.java | 2 -- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/src/main/java/net/raphimc/viaproxy/proxy/client2proxy/Client2ProxyHandler.java b/src/main/java/net/raphimc/viaproxy/proxy/client2proxy/Client2ProxyHandler.java index 6d71644..7addb80 100644 --- a/src/main/java/net/raphimc/viaproxy/proxy/client2proxy/Client2ProxyHandler.java +++ b/src/main/java/net/raphimc/viaproxy/proxy/client2proxy/Client2ProxyHandler.java @@ -279,15 +279,14 @@ public class Client2ProxyHandler extends SimpleChannelInboundHandler { this.proxyConnection.getChannel().writeAndFlush(newHandshakePacket).addListeners(ChannelFutureListener.FIRE_EXCEPTION_ON_FAILURE, (ChannelFutureListener) f2 -> { if (f2.isSuccess()) { - this.proxyConnection.setP2sConnectionState(intendedState.getConnectionState()); final UserConnection userConnection = this.proxyConnection.getUserConnection(); if (userConnection.has(CookieStorage.class) && TransferDataHolder.hasCookieStorage(this.proxyConnection.getC2P())) { userConnection.get(CookieStorage.class).cookies().putAll(TransferDataHolder.removeCookieStorage(this.proxyConnection.getC2P()).cookies()); } + this.proxyConnection.setP2sConnectionState(intendedState.getConnectionState()); + ChannelUtil.restoreAutoRead(this.proxyConnection.getC2P()); } }); - - ChannelUtil.restoreAutoRead(this.proxyConnection.getC2P()); }); } }, (ThrowingChannelFutureListener) f -> { diff --git a/src/main/java/net/raphimc/viaproxy/proxy/util/ExceptionUtil.java b/src/main/java/net/raphimc/viaproxy/proxy/util/ExceptionUtil.java index 54565e2..f2831b3 100644 --- a/src/main/java/net/raphimc/viaproxy/proxy/util/ExceptionUtil.java +++ b/src/main/java/net/raphimc/viaproxy/proxy/util/ExceptionUtil.java @@ -25,7 +25,6 @@ import net.raphimc.viaproxy.ViaProxy; import net.raphimc.viaproxy.proxy.session.ProxyConnection; import net.raphimc.viaproxy.util.logging.Logger; -import java.io.IOException; import java.lang.reflect.Field; import java.nio.channels.ClosedChannelException; @@ -45,7 +44,6 @@ public class ExceptionUtil { public static void handleNettyException(ChannelHandlerContext ctx, Throwable cause, ProxyConnection proxyConnection, boolean client2Proxy) { if (!ctx.channel().isOpen()) return; if (cause instanceof ClosedChannelException) return; - if (cause instanceof IOException) return; if (cause instanceof CloseAndReturn) { ctx.channel().close(); return;