From ca0a6a787a8a1ec3021fcfc8b2a24faa8092b1a7 Mon Sep 17 00:00:00 2001 From: leantk Date: Thu, 7 Sep 2017 10:36:35 -0400 Subject: [PATCH 1/2] Delay retrying to send telemetry if an exception is hit --- .../common/TransmissionNetworkOutput.java | 21 ++++++++++--------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/core/src/main/java/com/microsoft/applicationinsights/internal/channel/common/TransmissionNetworkOutput.java b/core/src/main/java/com/microsoft/applicationinsights/internal/channel/common/TransmissionNetworkOutput.java index 3476983fbcf..05957f6db11 100644 --- a/core/src/main/java/com/microsoft/applicationinsights/internal/channel/common/TransmissionNetworkOutput.java +++ b/core/src/main/java/com/microsoft/applicationinsights/internal/channel/common/TransmissionNetworkOutput.java @@ -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); @@ -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); + } } } From af83baf3657d0f32c7dff64be7a1629aefd3d9ba Mon Sep 17 00:00:00 2001 From: leantk Date: Fri, 15 Sep 2017 09:42:07 -0400 Subject: [PATCH 2/2] Updated changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 25626cc984e..eb685285406 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,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.