Skip to content

Commit 868d368

Browse files
committed
Fix proxy test hang: close both conns when either pipe direction exits
TestHTTPConnectDialer_Dial timed out after 10 minutes because handleProxyConn waited for both piping goroutines to signal done, but the target→client goroutine blocked on targetConn.Read indefinitely when the client closed its side. Added a sync.Once-guarded closeBoth() that closes both connections when either direction finishes, so the other goroutine unblocks immediately.
1 parent e5b9f9a commit 868d368

1 file changed

Lines changed: 13 additions & 1 deletion

File tree

pkg/git/proxy_test.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,17 @@ func handleProxyConn(t *testing.T, clientConn net.Conn, onConnect func(http.Resp
102102
}
103103
defer targetConn.Close()
104104

105-
// Pipe in both directions.
105+
// Pipe in both directions. When either direction encounters an error (e.g.
106+
// the client closes the connection), close both ends so the other goroutine
107+
// unblocks immediately instead of waiting forever for more data.
108+
var once sync.Once
109+
closeBoth := func() {
110+
once.Do(func() {
111+
targetConn.Close()
112+
clientConn.Close()
113+
})
114+
}
115+
106116
done := make(chan struct{}, 2)
107117
go func() {
108118
buf := make([]byte, 32*1024) // 32 KiB is a common I/O buffer size that balances memory use and throughput
@@ -115,6 +125,7 @@ func handleProxyConn(t *testing.T, clientConn net.Conn, onConnect func(http.Resp
115125
break
116126
}
117127
}
128+
closeBoth()
118129
done <- struct{}{}
119130
}()
120131
go func() {
@@ -128,6 +139,7 @@ func handleProxyConn(t *testing.T, clientConn net.Conn, onConnect func(http.Resp
128139
break
129140
}
130141
}
142+
closeBoth()
131143
done <- struct{}{}
132144
}()
133145
<-done

0 commit comments

Comments
 (0)