diff options
author | James Tucker <[email protected]> | 2025-01-21 10:32:18 -0800 |
---|---|---|
committer | GitHub <[email protected]> | 2025-01-21 10:32:18 -0800 |
commit | 48c7e53d7ac496fcc5c4cb44fdfffb00a696ef53 (patch) | |
tree | 0b8aed9f9ee359150077e5f2d5ca641d10efd24e | |
parent | 3ce58045626c8bc343a593c90354975e61b1817a (diff) |
gonet.TCPConn implements CloseRead and CloseWrite, but it is not a
net.TCPConn. Use an interface to look for CloseRead and CloseWrite so
that they are called on gonet.TCPConn.
Updates tailscale/corp#25169
Signed-off-by: James Tucker <[email protected]>
-rw-r--r-- | tcpproxy.go | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/tcpproxy.go b/tcpproxy.go index 1f03e32..745e2ba 100644 --- a/tcpproxy.go +++ b/tcpproxy.go @@ -355,16 +355,21 @@ func tcpConn(c net.Conn) (t *net.TCPConn, ok bool) { return nil, false } +type closeReader interface{ CloseRead() error } +type closeWriter interface{ CloseWrite() error } + func goCloseConn(c net.Conn) { go c.Close() } func closeRead(c net.Conn) { - if c, ok := tcpConn(c); ok { + // prefer the interfaces, for compatibility with e.g. gvisor/netstack. + if c, ok := UnderlyingConn(c).(closeReader); ok { c.CloseRead() } } func closeWrite(c net.Conn) { - if c, ok := tcpConn(c); ok { + // prefer the interfaces, for compatibility with e.g. gvisor/netstack. + if c, ok := UnderlyingConn(c).(closeWriter); ok { c.CloseWrite() } } |