Skip to content

Commit 598a28e

Browse files
authored
Merge branch 'master' into jainriya/npmliteCNSchanges
2 parents 23fba7e + 2bf6502 commit 598a28e

File tree

3 files changed

+36
-5
lines changed

3 files changed

+36
-5
lines changed

aitelemetry/telemetrywrapper.go

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ const (
2727
azurePublicCloudStr = "AzurePublicCloud"
2828
hostNameKey = "hostname"
2929
defaultTimeout = 10
30+
maxCloseTimeoutInSeconds = 30
3031
defaultBatchIntervalInSecs = 15
3132
defaultBatchSizeInBytes = 32768
3233
defaultGetEnvRetryCount = 5
@@ -330,8 +331,35 @@ func (th *telemetryHandle) Close(timeout int) {
330331
timeout = defaultTimeout
331332
}
332333

334+
// max wait is the minimum of the timeout and maxCloseTimeoutInSeconds
335+
maxWaitTimeInSeconds := timeout
336+
if maxWaitTimeInSeconds < maxCloseTimeoutInSeconds {
337+
maxWaitTimeInSeconds = maxCloseTimeoutInSeconds
338+
}
339+
333340
// wait for items to be sent otherwise timeout
334-
<-th.client.Channel().Close(time.Duration(timeout) * time.Second)
341+
// 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()
344+
select {
345+
case <-th.client.Channel().Close(time.Duration(timeout) * time.Second):
346+
// timeout specified for retries.
347+
348+
// If we got here, then all telemetry was submitted
349+
// successfully, and we can proceed to exiting.
350+
351+
case <-timer.C:
352+
// absolute timeout. This covers any
353+
// previous telemetry submission that may not have
354+
// completed before Close was called.
355+
356+
// There are a number of reasons we could have
357+
// reached here. We gave it a go, but telemetry
358+
// submission failed somewhere. Perhaps old events
359+
// were still retrying, or perhaps we're throttled.
360+
// Either way, we don't want to wait around for it
361+
// to complete, so let's just exit.
362+
}
335363

336364
// Remove diganostic message listener
337365
if th.diagListener != nil {

go.mod

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ go 1.23
55
toolchain go1.23.2
66

77
require (
8-
github.com/Azure/azure-sdk-for-go/sdk/azcore v1.16.0
8+
github.com/Azure/azure-sdk-for-go/sdk/azcore v1.17.0
99
github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.8.0
1010
github.com/Azure/azure-sdk-for-go/sdk/keyvault/azsecrets v0.12.0
1111
github.com/Masterminds/semver v1.5.0
@@ -160,4 +160,7 @@ replace (
160160
github.com/onsi/gomega => github.com/onsi/gomega v1.10.0
161161
)
162162

163-
retract v1.16.15 // typo in the version number.
163+
retract (
164+
v1.16.15 // typo in the version number.
165+
v1.16.16 // contains only retractions, has to be newer than 1.16.15.
166+
)

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMT
22
code.cloudfoundry.org/clock v0.0.0-20180518195852-02e53af36e6c/go.mod h1:QD9Lzhd/ux6eNQVUDVRJX/RKTigpewimNYBi7ivZKY8=
33
code.cloudfoundry.org/clock v1.0.0 h1:kFXWQM4bxYvdBw2X8BbBeXwQNgfoWv1vqAk2ZZyBN2o=
44
code.cloudfoundry.org/clock v1.0.0/go.mod h1:QD9Lzhd/ux6eNQVUDVRJX/RKTigpewimNYBi7ivZKY8=
5-
github.com/Azure/azure-sdk-for-go/sdk/azcore v1.16.0 h1:JZg6HRh6W6U4OLl6lk7BZ7BLisIzM9dG1R50zUk9C/M=
6-
github.com/Azure/azure-sdk-for-go/sdk/azcore v1.16.0/go.mod h1:YL1xnZ6QejvQHWJrX/AvhFl4WW4rqHVoKspWNVwFk0M=
5+
github.com/Azure/azure-sdk-for-go/sdk/azcore v1.17.0 h1:g0EZJwz7xkXQiZAI5xi9f3WWFYBlX1CPTrR+NDToRkQ=
6+
github.com/Azure/azure-sdk-for-go/sdk/azcore v1.17.0/go.mod h1:XCW7KnZet0Opnr7HccfUw1PLc4CjHqpcaxW8DHklNkQ=
77
github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.8.0 h1:B/dfvscEQtew9dVuoxqxrUKKv8Ih2f55PydknDamU+g=
88
github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.8.0/go.mod h1:fiPSssYvltE08HJchL04dOy+RD4hgrjph0cwGGMntdI=
99
github.com/Azure/azure-sdk-for-go/sdk/azidentity/cache v0.3.0 h1:+m0M/LFxN43KvULkDNfdXOgrjtg6UYJPFBJyuEcRCAw=

0 commit comments

Comments
 (0)