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.
This commit is contained in:
Matt Keeler 2022-05-27 16:52:03 -04:00 committed by GitHub
parent 9a13be3881
commit ead8e4a200
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 3 additions and 3 deletions

View File

@ -123,6 +123,9 @@ func (p *Proxy) Serve() error {
cfg = newCfg cfg = newCfg
case <-p.stopChan: case <-p.stopChan:
if p.service != nil {
p.service.Close()
}
return nil return nil
} }
} }
@ -153,7 +156,4 @@ func (p *Proxy) startListener(name string, l *Listener) error {
// called only once. // called only once.
func (p *Proxy) Close() { func (p *Proxy) Close() {
close(p.stopChan) close(p.stopChan)
if p.service != nil {
p.service.Close()
}
} }