Skip to content

Commit 7f81f77

Browse files
committed
Work around deadlock with Go tip (at Go rev f3f7bd5)
Not sure the root cause yet. See golang/go#25985.
1 parent 7efa37f commit 7f81f77

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

tcpproxy.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,8 @@ func UnderlyingConn(c net.Conn) net.Conn {
347347
return c
348348
}
349349

350+
func goCloseConn(c net.Conn) { go c.Close() }
351+
350352
// HandleConn implements the Target interface.
351353
func (dp *DialProxy) HandleConn(src net.Conn) {
352354
ctx := context.Background()
@@ -362,13 +364,13 @@ func (dp *DialProxy) HandleConn(src net.Conn) {
362364
dp.onDialError()(src, err)
363365
return
364366
}
365-
defer dst.Close()
367+
defer goCloseConn(dst)
366368

367369
if err = dp.sendProxyHeader(dst, src); err != nil {
368370
dp.onDialError()(src, err)
369371
return
370372
}
371-
defer src.Close()
373+
defer goCloseConn(src)
372374

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

0 commit comments

Comments
 (0)