fn: fixup possible go-routine leak (#1265)

This commit is contained in:
Tolga Ceylan
2018-10-05 17:02:18 -07:00
committed by GitHub
parent b7d53332d3
commit f10fab21bc

View File

@@ -784,10 +784,17 @@ func (s *hotSlot) dispatch(ctx context.Context, call *call) chan error {
}
common.Logger(ctx).WithField("resp", resp).Debug("Got resp from UDS socket")
// if ctx is canceled/timedout, then we close the body to unlock writeResp() below
defer resp.Body.Close()
ioErrChan := make(chan error, 1)
go func() {
ioErrChan <- writeResp(s.cfg.MaxResponseSize, resp, call.w)
}()
select {
case errApp <- writeResp(s.cfg.MaxResponseSize, resp, call.w):
case ioErr := <-ioErrChan:
errApp <- ioErr
case <-ctx.Done():
errApp <- ctx.Err()
}