From 93e569fa2395e4a3528683b4d1477cf958fb4ab5 Mon Sep 17 00:00:00 2001 From: Nuno Diegues Date: Mon, 30 Jan 2023 22:45:42 +0000 Subject: [PATCH] TUN-7146: Avoid data race in closing origin connection too early --- proxy/proxy.go | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/proxy/proxy.go b/proxy/proxy.go index 55c45dc0..6c404109 100644 --- a/proxy/proxy.go +++ b/proxy/proxy.go @@ -288,6 +288,7 @@ func (p *Proxy) proxyStream( return err } connectSpan.End() + defer originConn.Close() encodedSpans := tr.GetSpans() @@ -295,15 +296,6 @@ func (p *Proxy) proxyStream( return err } - streamCtx, cancel := context.WithCancel(ctx) - defer cancel() - - go func() { - // streamCtx is done if req is cancelled or if Stream returns - <-streamCtx.Done() - originConn.Close() - }() - originConn.Stream(ctx, rwa, p.log) return nil }