Repository navigation
[SDK-715] Mark network failures on API responses - #1114
franco-zalamena-iterable wants to merge 3 commits into
Conversation
fcf9119 to
597d4be
Compare
rtlsilva
left a comment
There was a problem hiding this comment.
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.
| apiResponse = IterableNetworkRetryClassifier.isNetworkFailure(e) | ||
| ? IterableApiResponse.networkFailure(requestResult, e.getMessage()) | ||
| : IterableApiResponse.failure(0, requestResult, null, e.getMessage()); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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>
597d4be to
690920e
Compare
📝 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
networkFailureflag onIterableApiResponseand 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.isNetworkFailuretreats 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 aCertificateExceptionorCertPathValidatorException, 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:testDebugUnitTestgives 846 tests, 21 skipped and 0 failures. Checkstyle, lint and the androidTest compile are green. OneIterableRequestTaskTestcase 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 inIterableNetworkRetryClassifierTest.🧾 Changelog
No customer facing changes
🤖 Generated with Claude Code