Skip to content

Commit 7e3ee76

Browse files
committed
fix: close timer in case it hasn't fired yet
Signed-off-by: Hunter Gregory <[email protected]>
1 parent df8cc53 commit 7e3ee76

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

aitelemetry/telemetrywrapper.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -339,14 +339,17 @@ func (th *telemetryHandle) Close(timeout int) {
339339

340340
// wait for items to be sent otherwise timeout
341341
// similar to the example in the appinsights-go repo: https://github.com/microsoft/ApplicationInsights-Go#shutdown
342+
timer := time.NewTimer(time.Duration(maxWaitTimeInSeconds) * time.Second)
343+
defer timer.Stop()
342344
select {
343345
case <-th.client.Channel().Close(time.Duration(timeout) * time.Second):
344346
// timeout specified for retries.
345347

346348
// If we got here, then all telemetry was submitted
347349
// successfully, and we can proceed to exiting.
348-
case <-time.After(time.Duration(maxWaitTimeInSeconds) * time.Second):
349-
// Thirty second absolute timeout. This covers any
350+
351+
case <-timer.C:
352+
// absolute timeout. This covers any
350353
// previous telemetry submission that may not have
351354
// completed before Close was called.
352355

0 commit comments

Comments
 (0)