TUN-7146: Avoid data race in closing origin connection too early

This commit is contained in:
Nuno Diegues 2023-01-30 22:45:42 +00:00 committed by João Oliveirinha
parent 207f4e2c8d
commit 93e569fa23
1 changed files with 1 additions and 9 deletions

View File

@ -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
}