Skip to content

[SDK-715] Mark network failures on API responses - #1114

Open
franco-zalamena-iterable wants to merge 1 commit into
feature/SDK-715-b-retry-injectionfrom
feature/SDK-715-c1-network-failure
Open

franco-zalamena-iterable wants to merge 1 commit into
feature/SDK-715-b-retry-injectionfrom
feature/SDK-715-c1-network-failure

Conversation

@franco-zalamena-iterable

@franco-zalamena-iterable franco-zalamena-iterable commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

📝 Summary

Adds a network failure marker to API responses and classifies which I/O errors count as network failures. Only tests read it for now.

🎟️ Jira Ticket: SDK-715

Epic: SDK-454

Stack, in order: #1111 (SDK-714), #1112, #1113, #1114, #1115. This is #1114.

📖 Description

Today every client side failure is reported as code 0, so the retry policy can't tell a timeout from a bad URL. This PR adds a networkFailure flag on IterableApiResponse and sets it when the request fails with a network error.

IterableNetworkRetryClassifier.isNetworkFailure treats timeouts, DNS failures, connection and socket errors and EOF as network failures. It also follows the cause chain, since on devices a dropped connection often comes as a plain IOException caused by an EOF or socket error. That covers TLS errors caused by a socket reset too. Other I/O errors, other TLS errors and bad URLs stay as plain code 0 failures.

Nothing in the request flow reads the flag yet, the legacy retry loop ignores it and a test pins that. It starts being used in #1115.

🧪 How to test?

./gradlew :iterableapi:testDebugUnitTest gives 846 tests, 21 skipped and 0 failures. Checkstyle, lint and the androidTest compile are green. The IterableRequestTaskTest cases use real refused, dropped and timed out connections, plus a test URL handler for the dropped case.

🧾 Changelog

No customer facing changes

🤖 Generated with Claude Code

An IOException from the request is marked as a network failure when it is
a timeout, DNS failure, socket error or EOF, or has an EOF or socket
error in its cause chain, which is how devices report a dropped
connection, including a TLS handshake closed by the server. Other I/O,
TLS and invalid-URL failures are not marked. Only the network retry
policy will read the marker; the legacy retry loop ignores it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@rtlsilva rtlsilva left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two small fixes to the PR description:

  • "Today every client side failure is reported as code 0" isn't quite right: a failure while reading a 200's body is reported as 200, and the code can also be -1.
  • The test count looks stale: a full run at the head gives 868 tests, 21 skipped.

Comment on lines +275 to +277
apiResponse = IterableNetworkRetryClassifier.isNetworkFailure(e)
? IterableApiResponse.networkFailure(requestResult, e.getMessage())
: IterableApiResponse.failure(0, requestResult, null, e.getMessage());

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This only marks failures thrown before the response headers arrive. If the connection drops or times out while the body is being read, the inner catch at :207-209 keeps just the message, so the marker isn't set, and on a 200 the response is still reported as code 200.

That's probably the most common network failure on mobile. Should we decide the rule explicitly (mark it, or not on a POST 200 since the server already processed it), put it in a comment, and add a test that sends headers and then drops the body?

}
Throwable cause = e.getCause();
for (int depth = 0; cause != null && depth < MAX_CAUSE_DEPTH; depth++) {
if (cause instanceof EOFException || cause instanceof SocketException) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two small things in the cause loop:

  • A malformed server certificate can end up here as SSLHandshakeException → CertificateException → … → EOFException. Bouncy Castle throws that EOF while parsing bytes already in memory, so it's not a network failure, but this loop marks it as one.
  • The top level accepts SocketTimeoutException and UnknownHostException, but causes don't, so an IOException caused by a timeout isn't marked.
Suggested change
if (cause instanceof EOFException || cause instanceof SocketException) {
if (cause instanceof CertificateException || cause instanceof CertPathValidatorException) {
return false;
}
if (cause instanceof SocketTimeoutException || cause instanceof UnknownHostException
|| cause instanceof EOFException || cause instanceof SocketException) {

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants