Skip to content

Commit

Permalink
fix: close timer in case it hasn't fired yet
Browse files Browse the repository at this point in the history
Signed-off-by: Hunter Gregory <[email protected]>
  • Loading branch information
huntergregory committed Jan 9, 2025
1 parent df8cc53 commit 7e3ee76
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions aitelemetry/telemetrywrapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down

0 comments on commit 7e3ee76

Please sign in to comment.