From 3d2ba153ab9b2da02986366d277d234eef5883f1 Mon Sep 17 00:00:00 2001 From: Andrey Belonogov Date: Mon, 23 Nov 2026 17:33:22 -0800 Subject: [PATCH] fix(events): retry TLS and certificate failures on the normal backoff The revised RETRY spec dropped TLS and certificate failures from the unexpected class, and the durability spec (section 9) lists them as normal. The analytics sender still sent SSLHandshakeException and SSLPeerUnverifiedException to the extended backoff (512 s to an hour), unlike the iOS SDK. A post with no response is now always normal. Co-authored-by: Cursor --- .../sdk/android/AnalyticsEventSender.java | 13 ++----- .../sdk/android/DeliveryRetryState.java | 3 +- .../sdk/android/AnalyticsEventSenderTest.java | 39 +++++++++++++++++++ 3 files changed, 44 insertions(+), 11 deletions(-) create mode 100644 launchdarkly-android-client-sdk/src/test/java/com/launchdarkly/sdk/android/AnalyticsEventSenderTest.java diff --git a/launchdarkly-android-client-sdk/src/main/java/com/launchdarkly/sdk/android/AnalyticsEventSender.java b/launchdarkly-android-client-sdk/src/main/java/com/launchdarkly/sdk/android/AnalyticsEventSender.java index 71ffe487..25735f86 100644 --- a/launchdarkly-android-client-sdk/src/main/java/com/launchdarkly/sdk/android/AnalyticsEventSender.java +++ b/launchdarkly-android-client-sdk/src/main/java/com/launchdarkly/sdk/android/AnalyticsEventSender.java @@ -12,10 +12,6 @@ import java.util.Date; import java.util.concurrent.TimeUnit; import java.util.zip.GZIPOutputStream; - -import javax.net.ssl.SSLHandshakeException; -import javax.net.ssl.SSLPeerUnverifiedException; - import okhttp3.Headers; import okhttp3.MediaType; import okhttp3.OkHttpClient; @@ -73,8 +69,8 @@ static final class Result { final boolean success; /** * For a failure, whether it is unlikely to pass soon: a 4xx other than a refusal of the payload - * ({@link LDUtil#isEventPayloadRefused}), 408 and 429, or a TLS or certificate failure. This only - * decides how long the next post waits. + * ({@link LDUtil#isEventPayloadRefused}), 408 and 429. This only decides how long the next post + * waits. */ final boolean unexpected; /** The HTTP status, or 0 where no response arrived. */ @@ -133,9 +129,8 @@ Result sendBatch(EventLogFormat.Payload payload, int eventCount, String payloadI return new Result(false, unexpected, response.code(), retryAfterMillis(response), null); } catch (IOException e) { logger.warn("Error posting events: {}", LogValues.exceptionSummary(e)); - // A certificate that will not validate is a misconfiguration, which waits like a refusal. - boolean unexpected = e instanceof SSLHandshakeException || e instanceof SSLPeerUnverifiedException; - return new Result(false, unexpected, 0, -1, null); + // No response, TLS and certificate failures included, takes the normal backoff. + return new Result(false, false, 0, -1, null); } } diff --git a/launchdarkly-android-client-sdk/src/main/java/com/launchdarkly/sdk/android/DeliveryRetryState.java b/launchdarkly-android-client-sdk/src/main/java/com/launchdarkly/sdk/android/DeliveryRetryState.java index fdb31706..596faaf1 100644 --- a/launchdarkly-android-client-sdk/src/main/java/com/launchdarkly/sdk/android/DeliveryRetryState.java +++ b/launchdarkly-android-client-sdk/src/main/java/com/launchdarkly/sdk/android/DeliveryRetryState.java @@ -73,8 +73,7 @@ synchronized void recordSuccess() { /** * @param unexpected whether the failure is unlikely to pass soon: a 4xx other than 400, 408, 413, 415, - * 422 and 429, or - * a TLS or certificate failure + * 422 and 429 * @param retryAfterMillis the wait the response asked for, or a negative number where it gave none * @return how long nothing may be posted */ diff --git a/launchdarkly-android-client-sdk/src/test/java/com/launchdarkly/sdk/android/AnalyticsEventSenderTest.java b/launchdarkly-android-client-sdk/src/test/java/com/launchdarkly/sdk/android/AnalyticsEventSenderTest.java new file mode 100644 index 00000000..2d0cc2ba --- /dev/null +++ b/launchdarkly-android-client-sdk/src/test/java/com/launchdarkly/sdk/android/AnalyticsEventSenderTest.java @@ -0,0 +1,39 @@ +package com.launchdarkly.sdk.android; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; + +import com.launchdarkly.sdk.android.subsystems.HttpConfiguration; +import com.launchdarkly.testhelpers.httptest.Handlers; +import com.launchdarkly.testhelpers.httptest.HttpServer; +import com.launchdarkly.testhelpers.httptest.ServerTLSConfiguration; + +import org.junit.Rule; +import org.junit.Test; + +import java.nio.charset.StandardCharsets; +import java.util.Collections; + +public class AnalyticsEventSenderTest { + @Rule + public LogCaptureRule logging = new LogCaptureRule(); + + @Test + public void certificateFailureTakesTheNormalBackoff() throws Exception { + // The client does not trust a self-signed certificate, so the post fails in the TLS handshake. + try (HttpServer server = HttpServer.startSecure(ServerTLSConfiguration.makeSelfSignedCertificate(), + Handlers.status(202)); + AnalyticsEventSender sender = new AnalyticsEventSender(LDUtil.makeHttpProperties( + new HttpConfiguration(2000, Collections.emptyMap(), null, false)), + false, logging.logger)) { + byte[] body = "[]".getBytes(StandardCharsets.UTF_8); + + AnalyticsEventSender.Result result = sender.sendBatch( + new EventLogFormat.Payload(body, body.length, 0), 0, "payload-id", server.getUri()); + + assertFalse(result.success); + assertEquals(0, result.status); + assertFalse(result.unexpected); + } + } +}