fix: connect to backend immediately on channel active for server-first protocols(#794) (#813)

- Closes #794 
- TCP port forwarding currently fails for server-first protocols (SMTP,
  FTP, SSH, PostgreSQL) because the backend connection is only established
  when the client sends data.
This commit is contained in:
Ronit Sabhaya
2025-12-01 16:52:57 -06:00
committed by GitHub
parent f0eb13176c
commit f394d87b26
+6 -3
View File
@@ -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 {