From 1261aadebefc21f88cc7071613c0e59298412c8f Mon Sep 17 00:00:00 2001 From: Mike Chiu Date: Tue, 25 Dec 2018 13:39:00 +0800 Subject: [PATCH] Fix fwatchdog timer memory leak issue Use timer.AfterFunc to make sure goroutine could be gc. Signed-off-by: Mike Chiu --- watchdog/handler.go | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/watchdog/handler.go b/watchdog/handler.go index 9ffa468b..7d8e7cea 100644 --- a/watchdog/handler.go +++ b/watchdog/handler.go @@ -109,10 +109,7 @@ func pipeRequest(config *WatchdogConfig, w http.ResponseWriter, r *http.Request, var timer *time.Timer if config.execTimeout > 0*time.Second { - timer = time.NewTimer(config.execTimeout) - - go func() { - <-timer.C + timer = time.AfterFunc(config.execTimeout, func() { log.Printf("Killing process: %s\n", config.faasProcess) if targetCmd != nil && targetCmd.Process != nil { ri.headerWritten = true @@ -125,7 +122,7 @@ func pipeRequest(config *WatchdogConfig, w http.ResponseWriter, r *http.Request, log.Printf("Killed process: %s - error %s\n", config.faasProcess, val.Error()) } } - }() + }) } // Write to pipe in separate go-routine to prevent blocking