Skip to content

Commit 1ffc7e9

Browse files
fix: connect to backend immediately on channel active for server-first protocols
1 parent cd7c3a1 commit 1ffc7e9

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

Sources/SocketForwarder/ConnectHandler.swift

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,6 @@ extension ConnectHandler: ChannelInboundHandler {
3535
typealias OutboundOut = ByteBuffer
3636

3737
func channelRead(context: ChannelHandlerContext, data: NIOAny) {
38-
if self.pendingBytes.isEmpty {
39-
self.connectToServer(context: context)
40-
}
4138
self.pendingBytes.append(data)
4239
}
4340

@@ -46,6 +43,12 @@ extension ConnectHandler: ChannelInboundHandler {
4643
self.log?[metadataKey: "proxy"] = "\(context.channel.localAddress?.description ?? "none")"
4744
self.log?[metadataKey: "server"] = "\(context.channel.remoteAddress?.description ?? "none")"
4845
}
46+
47+
func channelActive(context: ChannelHandlerContext) {
48+
self.log?.trace("frontend - channel active, connecting to backend")
49+
self.connectToServer(context: context)
50+
context.fireChannelActive()
51+
}
4952
}
5053

5154
extension ConnectHandler: RemovableChannelHandler {

0 commit comments

Comments
 (0)