Skip to content

Commit cbdef0c

Browse files
authored
Merge pull request #420 from leantk/users/leantk/backoff
Delay retrying to send telemetry if an exception is hit
2 parents 0de2fc2 + af83baf commit cbdef0c

File tree

2 files changed

+12
-10
lines changed

2 files changed

+12
-10
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
- Obsolete methods of `RequestTelemetry`: `getHttpMethod`, `setHttpMethod`.
1616
- Add option to configure instrumentation key via `APPINSIGHTS_INSTRUMENTATIONKEY` environment variable for consistency with other SDKs.
1717
- Fix the issue where `track(...)` of `TelemetryClient` class was overwriting the provided telemetry timestamp.
18+
- Changed the policy on failed sent requests to delay retrying for 5 minutes instead of immediately retrying.
1819

1920
## Version 1.0.9
2021
- Fix the issue of infinite retry and connection drain on certificate error by updating the version of http client packaged with the SDK.

core/src/main/java/com/microsoft/applicationinsights/internal/channel/common/TransmissionNetworkOutput.java

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ public boolean send(Transmission transmission) {
135135

136136
HttpResponse response = null;
137137
HttpPost request = null;
138+
boolean shouldBackoff = false;
138139
try {
139140
request = createTransmissionPostRequest(transmission);
140141
httpClient.enhanceRequest(request);
@@ -160,32 +161,32 @@ public boolean send(Transmission transmission) {
160161
}
161162
} catch (ConnectionPoolTimeoutException e) {
162163
InternalLogger.INSTANCE.error("Failed to send, connection pool timeout exception");
164+
shouldBackoff = true;
163165
} catch (SocketException e) {
164166
InternalLogger.INSTANCE.error("Failed to send, socket timeout exception");
165-
// backoff retry if no connection is found
166-
if (e instanceof ConnectException) {
167-
transmissionPolicyManager.suspendInSeconds(TransmissionPolicy.BLOCKED_BUT_CAN_BE_PERSISTED, DEFAULT_BACKOFF_TIME_SECONDS);
168-
}
167+
shouldBackoff = true;
169168
} catch (UnknownHostException e) {
170169
InternalLogger.INSTANCE.error("Failed to send, wrong host address or cannot reach address due to network issues, exception: %s", e.getMessage());
171-
// backoff retry if host unknown
172-
transmissionPolicyManager.suspendInSeconds(TransmissionPolicy.BLOCKED_BUT_CAN_BE_PERSISTED, DEFAULT_BACKOFF_TIME_SECONDS);
170+
shouldBackoff = true;
173171
} catch (IOException ioe) {
174172
InternalLogger.INSTANCE.error("Failed to send, exception: %s", ioe.getMessage());
175-
// backoff retry if no connection is found
176-
if (ioe instanceof ConnectTimeoutException) {
177-
transmissionPolicyManager.suspendInSeconds(TransmissionPolicy.BLOCKED_BUT_CAN_BE_PERSISTED, DEFAULT_BACKOFF_TIME_SECONDS);
178-
}
173+
shouldBackoff = true;
179174
} catch (Exception e) {
180175
InternalLogger.INSTANCE.error("Failed to send, unexpected exception: %s", e.getMessage());
176+
shouldBackoff = true;
181177
} catch (Throwable t) {
182178
InternalLogger.INSTANCE.error("Failed to send, unexpected error: %s", t.getMessage());
179+
shouldBackoff = true;
183180
}
184181
finally {
185182
if (request != null) {
186183
request.releaseConnection();
187184
}
188185
httpClient.dispose(response);
186+
// backoff before trying again
187+
if (shouldBackoff) {
188+
transmissionPolicyManager.suspendInSeconds(TransmissionPolicy.BLOCKED_BUT_CAN_BE_PERSISTED, DEFAULT_BACKOFF_TIME_SECONDS);
189+
}
189190
}
190191
}
191192

0 commit comments

Comments
 (0)