From ead8e4a20082b8cd63ee6b90bf9e9677ff963d2f Mon Sep 17 00:00:00 2001 From: Matt Keeler Date: Fri, 27 May 2022 16:52:03 -0400 Subject: [PATCH] Fix race during proxy closing (#13283) p.service is written to within the Serve method. The Serve method also waits for the stopChan to be closed. The race was between Close being called on the proxy causing Close on the service which was written to around the same time in the Serve method. The fix is to have Serve be responsible for closing p.service. --- connect/proxy/proxy.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/connect/proxy/proxy.go b/connect/proxy/proxy.go index f77d96ca93..fcce311560 100644 --- a/connect/proxy/proxy.go +++ b/connect/proxy/proxy.go @@ -123,6 +123,9 @@ func (p *Proxy) Serve() error { cfg = newCfg case <-p.stopChan: + if p.service != nil { + p.service.Close() + } return nil } } @@ -153,7 +156,4 @@ func (p *Proxy) startListener(name string, l *Listener) error { // called only once. func (p *Proxy) Close() { close(p.stopChan) - if p.service != nil { - p.service.Close() - } }