From 40f4bd069ed2c82215dc0dd6eb24d5f557c8a108 Mon Sep 17 00:00:00 2001 From: Hayden <64056131+hay-kot@users.noreply.github.com> Date: Tue, 21 Mar 2023 10:52:17 -0800 Subject: [PATCH] fix potential memory leak with time.After --- backend/app/api/app.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/backend/app/api/app.go b/backend/app/api/app.go index a84b9ae..0f44297 100644 --- a/backend/app/api/app.go +++ b/backend/app/api/app.go @@ -37,8 +37,11 @@ func new(conf *config.Config) *app { } func (a *app) startBgTask(t time.Duration, fn func()) { + timer := time.NewTimer(t) + for { + timer.Reset(t) a.server.Background(fn) - time.Sleep(t) + <-timer.C } }