Fixed proxy connect race condition
Some checks are pending
build-docker / build (push) Waiting to run
build / build (push) Waiting to run

This commit is contained in:
RaphiMC 2024-07-19 15:31:22 +02:00
parent be14bbf6f4
commit 57d1af5427
No known key found for this signature in database
GPG key ID: 0F6BB0657A03AC94
2 changed files with 2 additions and 5 deletions

View file

@ -279,15 +279,14 @@ public class Client2ProxyHandler extends SimpleChannelInboundHandler<IPacket> {
this.proxyConnection.getChannel().writeAndFlush(newHandshakePacket).addListeners(ChannelFutureListener.FIRE_EXCEPTION_ON_FAILURE, (ChannelFutureListener) f2 -> { this.proxyConnection.getChannel().writeAndFlush(newHandshakePacket).addListeners(ChannelFutureListener.FIRE_EXCEPTION_ON_FAILURE, (ChannelFutureListener) f2 -> {
if (f2.isSuccess()) { if (f2.isSuccess()) {
this.proxyConnection.setP2sConnectionState(intendedState.getConnectionState());
final UserConnection userConnection = this.proxyConnection.getUserConnection(); final UserConnection userConnection = this.proxyConnection.getUserConnection();
if (userConnection.has(CookieStorage.class) && TransferDataHolder.hasCookieStorage(this.proxyConnection.getC2P())) { if (userConnection.has(CookieStorage.class) && TransferDataHolder.hasCookieStorage(this.proxyConnection.getC2P())) {
userConnection.get(CookieStorage.class).cookies().putAll(TransferDataHolder.removeCookieStorage(this.proxyConnection.getC2P()).cookies()); 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 -> { }, (ThrowingChannelFutureListener) f -> {

View file

@ -25,7 +25,6 @@ import net.raphimc.viaproxy.ViaProxy;
import net.raphimc.viaproxy.proxy.session.ProxyConnection; import net.raphimc.viaproxy.proxy.session.ProxyConnection;
import net.raphimc.viaproxy.util.logging.Logger; import net.raphimc.viaproxy.util.logging.Logger;
import java.io.IOException;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.nio.channels.ClosedChannelException; import java.nio.channels.ClosedChannelException;
@ -45,7 +44,6 @@ public class ExceptionUtil {
public static void handleNettyException(ChannelHandlerContext ctx, Throwable cause, ProxyConnection proxyConnection, boolean client2Proxy) { public static void handleNettyException(ChannelHandlerContext ctx, Throwable cause, ProxyConnection proxyConnection, boolean client2Proxy) {
if (!ctx.channel().isOpen()) return; if (!ctx.channel().isOpen()) return;
if (cause instanceof ClosedChannelException) return; if (cause instanceof ClosedChannelException) return;
if (cause instanceof IOException) return;
if (cause instanceof CloseAndReturn) { if (cause instanceof CloseAndReturn) {
ctx.channel().close(); ctx.channel().close();
return; return;