Skip to content

Commit 48c7e53

Browse files
authored
tcpproxy: support half-close with gvisor conns (#46)
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 <jftucker@gmail.com>
1 parent 3ce5804 commit 48c7e53

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

tcpproxy.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -355,16 +355,21 @@ func tcpConn(c net.Conn) (t *net.TCPConn, ok bool) {
355355
return nil, false
356356
}
357357

358+
type closeReader interface{ CloseRead() error }
359+
type closeWriter interface{ CloseWrite() error }
360+
358361
func goCloseConn(c net.Conn) { go c.Close() }
359362

360363
func closeRead(c net.Conn) {
361-
if c, ok := tcpConn(c); ok {
364+
// prefer the interfaces, for compatibility with e.g. gvisor/netstack.
365+
if c, ok := UnderlyingConn(c).(closeReader); ok {
362366
c.CloseRead()
363367
}
364368
}
365369

366370
func closeWrite(c net.Conn) {
367-
if c, ok := tcpConn(c); ok {
371+
// prefer the interfaces, for compatibility with e.g. gvisor/netstack.
372+
if c, ok := UnderlyingConn(c).(closeWriter); ok {
368373
c.CloseWrite()
369374
}
370375
}

0 commit comments

Comments
 (0)