Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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. */
Expand Down Expand Up @@ -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);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -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);
}
}
}