diff --git a/Sources/SocketForwarder/ConnectHandler.swift b/Sources/SocketForwarder/ConnectHandler.swift index ef74db0b..c4e9c61e 100644 --- a/Sources/SocketForwarder/ConnectHandler.swift +++ b/Sources/SocketForwarder/ConnectHandler.swift @@ -35,9 +35,6 @@ extension ConnectHandler: ChannelInboundHandler { typealias OutboundOut = ByteBuffer func channelRead(context: ChannelHandlerContext, data: NIOAny) { - if self.pendingBytes.isEmpty { - self.connectToServer(context: context) - } self.pendingBytes.append(data) } @@ -46,6 +43,12 @@ extension ConnectHandler: ChannelInboundHandler { self.log?[metadataKey: "proxy"] = "\(context.channel.localAddress?.description ?? "none")" self.log?[metadataKey: "server"] = "\(context.channel.remoteAddress?.description ?? "none")" } + + func channelActive(context: ChannelHandlerContext) { + self.log?.trace("frontend - channel active, connecting to backend") + self.connectToServer(context: context) + context.fireChannelActive() + } } extension ConnectHandler: RemovableChannelHandler {