Skip to content

tcpproxy: support half-close with gvisor conns #46

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 21, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions tcpproxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}
Expand Down