From 13a69bda82dd2ace404f61acf4c3c4abd5f0708b Mon Sep 17 00:00:00 2001 From: Michael Schurter Date: Thu, 30 Nov 2017 20:37:13 -0800 Subject: [PATCH] Add defensive check to safeguard from future #3342s I hate adding "this should never happen" checks, but causing a tight loop that OOMs Nomad is just too easy in this code otherwise. --- command/agent/fs_endpoint.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/command/agent/fs_endpoint.go b/command/agent/fs_endpoint.go index 1c8e603026c..daf41422e8a 100644 --- a/command/agent/fs_endpoint.go +++ b/command/agent/fs_endpoint.go @@ -923,6 +923,20 @@ func (s *HTTPServer) logs(follow, plain bool, offset int64, return nil } + // defensively check to make sure StreamFramer hasn't stopped + // running to avoid tight loops with goroutine leaks as in + // #3342 + select { + case <-framer.ExitCh(): + err := parseFramerErr(framer.Err()) + if err == syscall.EPIPE { + // EPIPE just means the connection was closed + return nil + } + return err + default: + } + // Since we successfully streamed, update the overall offset/idx. offset = int64(0) nextIdx = idx + 1