From f10fab21bcefb52bc002f14ddc9a18e9f611b3b5 Mon Sep 17 00:00:00 2001 From: Tolga Ceylan Date: Fri, 5 Oct 2018 17:02:18 -0700 Subject: [PATCH] fn: fixup possible go-routine leak (#1265) --- api/agent/agent.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/api/agent/agent.go b/api/agent/agent.go index 042fa27fa..cb52f7ded 100644 --- a/api/agent/agent.go +++ b/api/agent/agent.go @@ -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() }