From de9b413bc273390e315ecc3c1c4f237f345f0038 Mon Sep 17 00:00:00 2001 From: Matthew Penner Date: Mon, 1 Feb 2021 20:09:24 -0700 Subject: [PATCH] Call cancel function for context to not leak resources --- server/power.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/server/power.go b/server/power.go index 0e08953..e587c8a 100644 --- a/server/power.go +++ b/server/power.go @@ -83,7 +83,9 @@ func (s *Server) HandlePowerAction(action PowerAction, waitSeconds ...int) error // Determines if we should wait for the lock or not. If a value greater than 0 is passed // into this function we will wait that long for a lock to be acquired. if len(waitSeconds) > 0 && waitSeconds[0] != 0 { - ctx, _ := context.WithTimeout(context.Background(), time.Second*time.Duration(waitSeconds[0])) + ctx, cancel := context.WithTimeout(context.Background(), time.Second*time.Duration(waitSeconds[0])) + defer cancel() + // Attempt to acquire a lock on the power action lock for up to 30 seconds. If more // time than that passes an error will be propagated back up the chain and this // request will be aborted.