Skip to content

Conversation

@Ronitsabhaya75
Copy link
Contributor

@Ronitsabhaya75 Ronitsabhaya75 commented Oct 27, 2025

Type of Change

  • Bug fix
  • New feature
  • Breaking change
  • Documentation update

Motivation and Context

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.

Current behavior in ConnectHandler.swift:

func channelRead(context: ChannelHandlerContext, data: NIOAny) {
    if self.pendingBytes.isEmpty {
        self.connectToServer(context: context)  // Only connects on first data!
    }
}

This breaks any protocol where the server speaks first.

The fix:
Connect to the backend immediately when the channel becomes active, not when data arrives. This allows bidirectional communication from the start.

Testing

  • Tested locally
  • Added/updated tests
  • Added/updated docs

@Ronitsabhaya75 Ronitsabhaya75 force-pushed the fix-tcp-port-forwarding branch from 58d6c11 to 385f421 Compare October 27, 2025 23:13
@liufeng-xiwo
Copy link

The problem also breaks connecting mysql service with port forwarding.

@Ronitsabhaya75
Copy link
Contributor Author

The problem also breaks connecting mysql service with port forwarding.

can you go bit in detail please.

@Ronitsabhaya75 Ronitsabhaya75 force-pushed the fix-tcp-port-forwarding branch 2 times, most recently from d924d1f to 1ffc7e9 Compare November 3, 2025 13:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: TCP Port Forwarding Fails: Connection succeeds but data stream times out

2 participants