From cf3da592a511fc938f5d39a44b438e54b6ae8033 Mon Sep 17 00:00:00 2001 From: Pavel Skuratovich Date: Wed, 18 Jan 2023 00:20:26 +0300 Subject: [PATCH] Force TCP KeepAlive on both sides of proxied connection --- main.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/main.go b/main.go index aa3cc7d..1ca3938 100644 --- a/main.go +++ b/main.go @@ -181,6 +181,12 @@ func proxy(local io.ReadWriteCloser, remoteAddr *net.TCPAddr) { return } + local.(*net.TCPConn).SetKeepAlive(true) + local.(*net.TCPConn).SetKeepAlivePeriod(5 * time.Second) + + remote.(*net.TCPConn).SetKeepAlive(true) + remote.(*net.TCPConn).SetKeepAlivePeriod(5 * time.Second) + go pipe(local, remote) go pipe(remote, local) }