diff --git a/common/net/io.go b/common/net/io.go new file mode 100644 index 00000000..5bb4f002 --- /dev/null +++ b/common/net/io.go @@ -0,0 +1,11 @@ +package net + +import "io" + +type ReadOnlyReader struct { + io.Reader +} + +type WriteOnlyWriter struct { + io.Writer +} diff --git a/tunnel/connection.go b/tunnel/connection.go index 77671a4b..b3554a47 100644 --- a/tunnel/connection.go +++ b/tunnel/connection.go @@ -10,6 +10,7 @@ import ( "time" "github.com/Dreamacro/clash/adapters/inbound" + N "github.com/Dreamacro/clash/common/net" "github.com/Dreamacro/clash/common/pool" "github.com/Dreamacro/clash/component/resolver" C "github.com/Dreamacro/clash/constant" @@ -141,14 +142,16 @@ func relay(leftConn, rightConn net.Conn) { go func() { buf := pool.Get(pool.RelayBufferSize) - _, err := io.CopyBuffer(leftConn, rightConn, buf) + // Wrapping to avoid using *net.TCPConn.(ReadFrom) + // See also https://github.com/Dreamacro/clash/pull/1209 + _, err := io.CopyBuffer(N.WriteOnlyWriter{Writer: leftConn}, N.ReadOnlyReader{Reader: rightConn}, buf) pool.Put(buf) leftConn.SetReadDeadline(time.Now()) ch <- err }() buf := pool.Get(pool.RelayBufferSize) - io.CopyBuffer(rightConn, leftConn, buf) + io.CopyBuffer(N.WriteOnlyWriter{Writer: rightConn}, N.ReadOnlyReader{Reader: leftConn}, buf) pool.Put(buf) rightConn.SetReadDeadline(time.Now()) <-ch