From 7e3ee760460cdd70940ee08c0e6fc86d7172376d Mon Sep 17 00:00:00 2001 From: Hunter Gregory <42728408+huntergregory@users.noreply.github.com> Date: Wed, 8 Jan 2025 16:34:03 -0800 Subject: [PATCH] fix: close timer in case it hasn't fired yet Signed-off-by: Hunter Gregory <42728408+huntergregory@users.noreply.github.com> --- aitelemetry/telemetrywrapper.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/aitelemetry/telemetrywrapper.go b/aitelemetry/telemetrywrapper.go index 92d6fb85c2..7caacf2979 100644 --- a/aitelemetry/telemetrywrapper.go +++ b/aitelemetry/telemetrywrapper.go @@ -339,14 +339,17 @@ func (th *telemetryHandle) Close(timeout int) { // wait for items to be sent otherwise timeout // similar to the example in the appinsights-go repo: https://github.com/microsoft/ApplicationInsights-Go#shutdown + timer := time.NewTimer(time.Duration(maxWaitTimeInSeconds) * time.Second) + defer timer.Stop() select { case <-th.client.Channel().Close(time.Duration(timeout) * time.Second): // timeout specified for retries. // If we got here, then all telemetry was submitted // successfully, and we can proceed to exiting. - case <-time.After(time.Duration(maxWaitTimeInSeconds) * time.Second): - // Thirty second absolute timeout. This covers any + + case <-timer.C: + // absolute timeout. This covers any // previous telemetry submission that may not have // completed before Close was called.