Skip to content

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

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

franco-zalamena-iterable wants to merge 3 commits 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 a request that fails before the response headers arrive is reported as code 0 whatever the cause, 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 that failure is a network error. A failure while reading the body keeps the status code, for example 200, and is not marked since the server already answered. The code can also be -1 when the response isn't valid HTTP.

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, and a timeout or DNS failure wrapped in another IOException counts too. That covers TLS errors caused by a socket reset too. The walk stops at a CertificateException or CertPathValidatorException, since a certificate parser can throw EOF on bytes in memory, so a certificate error is never a network failure. 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. One IterableRequestTaskTest case sends a refused connection, a dropped connection from a test URL handler and a bad URL through the real catch. The cause chains, including the wrapped timeout, DNS, TLS and certificate cases, are tables in IterableNetworkRetryClassifierTest.

🧾 Changelog

No customer facing changes

🤖 Generated with Claude Code

@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?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I'm keeping a failed 2xx terminal for both GET and POST, since the server already answered the request, so a body read failure is not marked here. #1115 has the rule as a comment on classify, and a 200 whose body breaks mid-read keeps its code and is not retried gives a GET and a POST 200 headers over a real socket and then drops the connection mid-body. It checks the response keeps code 200, isn't marked and isn't retried.

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>
A certificate parser can throw an EOF on bytes already in memory, so an
IOException with a CertificateException or CertPathValidatorException in
its cause chain is no longer marked as a network failure, whatever is
below it. A timeout or DNS failure in the cause chain is now marked, the
same as at the top level. An SSL exception caused by a socket error
still counts.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The cause chain tables move to the classifier test, where
isNetworkFailure lives, and the two real socket TLS tests become rows
there. The dropped connection and read timeout socket tests repeated
shapes those tables already cover, and the read timeout one blocked for
3 s on every run.

One connection test keeps the catch wiring: a refused connection, the
device-style dropped connection and a bad URL. The test protocol
handler now throws only that device shape. Test-only change.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@franco-zalamena-iterable
franco-zalamena-iterable force-pushed the feature/SDK-715-c1-network-failure branch from 597d4be to 690920e Compare November 27, 2026 21:48
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