diff --git a/CHANGELOG.md b/CHANGELOG.md index a1f77632a06..3264ef31e6a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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. 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); + } } }