Skip to content

Commit

Permalink
fix instant RST/FIN after SYN/SYN-ACK/ACK (#12554)
Browse files Browse the repository at this point in the history
Motivation:

If you close the connection before the backend connects, the backend
will keep connected until timeout. If you add logging, you will have sth
like that:
```
12:57:57.398 ProxyFrontendHandler channelActive
12:57:57.405 ProxyFrontendHandler channelInactive
12:57:57.431 ProxyBackendHandler channelActive
```
Ping between backend and frontend was about 50 ms, and the time
difference between connecting and disconnecting was about 1 ms.
Example code in Java to test frontend/backend:
```
        while (true) {
            System.out.println("tick");
            try {
                Socket socket = new Socket();
                socket.connect(new InetSocketAddress("127.0.0.1", 8443), 3000);
                socket.close();
                Thread.sleep(100);
            } catch (IOException ex) {
                ex.printStackTrace();
            }
        }
```


Modification:

Close backend connection if inbound is not active.
  • Loading branch information
adiantek committed May 22, 2023
1 parent 92f67bf commit 2822dfd
Showing 1 changed file with 5 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,11 @@ public HexDumpProxyBackendHandler(Channel inboundChannel) {

@Override
public void channelActive(ChannelHandlerContext ctx) {
ctx.read();
if (!inboundChannel.isActive()) {
HexDumpProxyFrontendHandler.closeOnFlush(ctx.channel());
} else {
ctx.read();
}
}

@Override
Expand Down

0 comments on commit 2822dfd

Please sign in to comment.