Skip to content

fix: read Android's dropped connection as Offline, and apply nothing when a values request fails - #9

Merged
crazeydave merged 1 commit into
mainfrom
fix/android-connection-abort-is-offline
Oct 5, 2026
Merged

crazeydave merged 1 commit into
mainfrom
fix/android-connection-abort-is-offline

Conversation

@crazeydave

Copy link
Copy Markdown
Contributor

Found on the Register tablet on 2026-10-04, in the app log under files/logs. The app was backgrounded mid-sync, the connection dropped, and the start surfaced as "Unobserved exception in fire-and-forget task (FreedomStartupSync)" instead of a SyncResult with status Offline. The next sync succeeded.

AndroidMessageHandler does not throw HttpRequestException. It throws System.Net.WebException (inner Java.Net.SocketException: Software caused connection abort). FreedomApi.SendAsync only caught HttpRequestException and an unrequested TaskCanceledException, so the exception escaped SyncAsync → ApplyManifestAsync → SendAsync<ValuesResponse>.

The fix:

  • FreedomApi treats WebException and IOException as no answer, alongside the two it already caught. Reads retry as before; the response is Unreachable. Both are BCL types, so Freedom.Client stays plain net10.0 with no Android reference. A caller's own cancellation is still not mistaken for no network.
  • A values request that fails now changes nothing. This covers no answer and an error status. Earlier batches and removals are not applied either, so the store stays exactly what its ETag describes and the next start retries cleanly. Before, earlier batches and removals were kept with the ETag withheld.
  • That start is reported the way a failed manifest would be. It is Offline for no answer and ServerError for a 5xx or 429. A 401 or a plugin refusal on the values request clears the device, exactly as it would on the manifest. Before, the start came back UpToDate or Updated with a "partly updated" message, which the ServerError case in StartupSync.feature never checked.
  • Unchanged: a secret that will not open, missing keys, or a value that changed again mid-sync still apply the rest and withhold the ETag. Those are the server answering, not the request failing.

Tests:

  • FakeFreedomServer.ValuesFailure and ConnectionAborted() reproduce the exception Android's handler throws.
  • FreedomApiTests checks WebException and IOException on a read (retried) and on a write (not retried), and that a caller's own cancellation still throws.
  • FreedomClientTests checks three things:
    • a dropped connection mid-sync leaves values, removals, ETag and VerifiedAt untouched, raises no ConfigChanged, and the next start repairs it;
    • a failure in the second of two batches discards the first;
    • a values 503 is ServerError.
  • Offline.feature has a new rule for a connection lost part-way through a start, with two scenarios. StartupSync.feature now asserts ServerError for its existing scenario where the values could not be fetched.

Against the client code before this change, 5 of the new tests and 3 scenarios fail. With it: 86 tests pass, and 36 scenarios pass with 6 manual ones skipped. dotnet format --verify-no-changes is clean for all four projects. The MAUI project is untouched.

…when a values request fails

AndroidMessageHandler reports a dropped connection as WebException (inner
Java.Net.SocketException: Software caused connection abort), not
HttpRequestException. FreedomApi only caught the latter, so on the Register
tablet on 2026-10-04 a connection dropped as the app was backgrounded
escaped SyncAsync from the values request instead of returning Offline.

- FreedomApi treats WebException and IOException as no answer, alongside
  HttpRequestException and an unrequested timeout. No Android types are
  referenced; both are BCL.
- A values request that gets no answer or an error now abandons the whole
  sync: nothing is applied, not earlier batches nor removals, so the store
  stays exactly what its ETag describes and the next start retries cleanly.
  It is reported as the manifest request would have been (Offline,
  ServerError, ...), where before it came back UpToDate or Updated.
@crazeydave
crazeydave merged commit 73a1f3c into main Oct 5, 2026
6 checks passed
@crazeydave
crazeydave deleted the fix/android-connection-abort-is-offline branch October 5, 2026 08:21
crazeydave added a commit to bleedingdeacons/register that referenced this pull request Oct 5, 2026
… not an unobserved exception (#62)

On 2026-10-04 the tablet was backgrounded during the startup sync. Android's
handler threw WebException, which Freedom.Client 0.1.1 did not recognise, and
it escaped FreedomClient.SyncAsync as "Unobserved exception in fire-and-forget
task (FreedomStartupSync)". freedom-sharp 0.2.1 (bleedingdeacons/freedom-sharp#9)
reads it as no answer, reports Offline, and applies nothing when a values
request fails, so the next start retries cleanly.

Also takes 0.2.0, which builds Freedom.Client.Maui for every head; Register
still references it on Android only.
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.

1 participant