Skip to content

Commit

Permalink
Merge pull request #420 from leantk/users/leantk/backoff
Browse files Browse the repository at this point in the history
Delay retrying to send telemetry if an exception is hit
  • Loading branch information
dhaval24 authored Sep 15, 2017
2 parents 0de2fc2 + af83baf commit cbdef0c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
- Obsolete methods of `RequestTelemetry`: `getHttpMethod`, `setHttpMethod`.
- Add option to configure instrumentation key via `APPINSIGHTS_INSTRUMENTATIONKEY` environment variable for consistency with other SDKs.
- Fix the issue where `track(...)` of `TelemetryClient` class was overwriting the provided telemetry timestamp.
- Changed the policy on failed sent requests to delay retrying for 5 minutes instead of immediately retrying.

## Version 1.0.9
- Fix the issue of infinite retry and connection drain on certificate error by updating the version of http client packaged with the SDK.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ public boolean send(Transmission transmission) {

HttpResponse response = null;
HttpPost request = null;
boolean shouldBackoff = false;
try {
request = createTransmissionPostRequest(transmission);
httpClient.enhanceRequest(request);
Expand All @@ -160,32 +161,32 @@ public boolean send(Transmission transmission) {
}
} catch (ConnectionPoolTimeoutException e) {
InternalLogger.INSTANCE.error("Failed to send, connection pool timeout exception");
shouldBackoff = true;
} catch (SocketException e) {
InternalLogger.INSTANCE.error("Failed to send, socket timeout exception");
// backoff retry if no connection is found
if (e instanceof ConnectException) {
transmissionPolicyManager.suspendInSeconds(TransmissionPolicy.BLOCKED_BUT_CAN_BE_PERSISTED, DEFAULT_BACKOFF_TIME_SECONDS);
}
shouldBackoff = true;
} catch (UnknownHostException e) {
InternalLogger.INSTANCE.error("Failed to send, wrong host address or cannot reach address due to network issues, exception: %s", e.getMessage());
// backoff retry if host unknown
transmissionPolicyManager.suspendInSeconds(TransmissionPolicy.BLOCKED_BUT_CAN_BE_PERSISTED, DEFAULT_BACKOFF_TIME_SECONDS);
shouldBackoff = true;
} catch (IOException ioe) {
InternalLogger.INSTANCE.error("Failed to send, exception: %s", ioe.getMessage());
// backoff retry if no connection is found
if (ioe instanceof ConnectTimeoutException) {
transmissionPolicyManager.suspendInSeconds(TransmissionPolicy.BLOCKED_BUT_CAN_BE_PERSISTED, DEFAULT_BACKOFF_TIME_SECONDS);
}
shouldBackoff = true;
} catch (Exception e) {
InternalLogger.INSTANCE.error("Failed to send, unexpected exception: %s", e.getMessage());
shouldBackoff = true;
} catch (Throwable t) {
InternalLogger.INSTANCE.error("Failed to send, unexpected error: %s", t.getMessage());
shouldBackoff = true;
}
finally {
if (request != null) {
request.releaseConnection();
}
httpClient.dispose(response);
// backoff before trying again
if (shouldBackoff) {
transmissionPolicyManager.suspendInSeconds(TransmissionPolicy.BLOCKED_BUT_CAN_BE_PERSISTED, DEFAULT_BACKOFF_TIME_SECONDS);
}
}
}

Expand Down

0 comments on commit cbdef0c

Please sign in to comment.