Skip to content

Commit

Permalink
Work around deadlock with Go tip (at Go rev f3f7bd5)
Browse files Browse the repository at this point in the history
Not sure the root cause yet. See golang/go#25985.
  • Loading branch information
bradfitz committed Jun 20, 2018
1 parent 7efa37f commit 7f81f77
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions tcpproxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,8 @@ func UnderlyingConn(c net.Conn) net.Conn {
return c
}

func goCloseConn(c net.Conn) { go c.Close() }

// HandleConn implements the Target interface.
func (dp *DialProxy) HandleConn(src net.Conn) {
ctx := context.Background()
Expand All @@ -362,13 +364,13 @@ func (dp *DialProxy) HandleConn(src net.Conn) {
dp.onDialError()(src, err)
return
}
defer dst.Close()
defer goCloseConn(dst)

if err = dp.sendProxyHeader(dst, src); err != nil {
dp.onDialError()(src, err)
return
}
defer src.Close()
defer goCloseConn(src)

if ka := dp.keepAlivePeriod(); ka > 0 {
if c, ok := UnderlyingConn(src).(*net.TCPConn); ok {
Expand Down

0 comments on commit 7f81f77

Please sign in to comment.