Skip to content

Don't crash when a fetch outlives the map screen that started it - #296

Merged
parawanderer merged 1 commit into
mainfrom
fix/fetch-on-a-replaced-account
Nov 21, 2026
Merged

parawanderer merged 1 commit into
mainfrom
fix/fetch-on-a-replaced-account

Conversation

@parawanderer

Copy link
Copy Markdown
Owner

Summary

The app crashed on leaving Settings after a theme change. Found while testing #273, but main has it too: #273 only changes comments in PythonLock.

What happens:

  1. The theme change rebuilds MapsActivity. The new one restores a fresh account, and PythonAppleService.setup closes the old one under PythonLock.
  2. The old screen's location fetch was queued on that lock. It runs next, on the closed account, and fails with HttpSession has been closed and cannot be used.
  3. The old screen has already disposed its subscription, so RxJava can't deliver the error, and its default handler kills the process (UndeliverableException).

Changes

  • PythonAppleService.getLastReports / getReportsBetween pick the account after taking the lock. If the service was replaced while the fetch waited, they use the current account; after a sign-out, they return an empty result. HistoryViewActivity also holds an instance, so this covers it.
  • OpenAirTagApplication installs UndeliverableErrors.handler() as RxJava's error handler. An UndeliverableException is logged; anything else still goes to the thread's uncaught-exception handler, so real bugs still crash.

Testing

  • UndeliverableErrorsTest (JVM): a fetch whose subscriber is disposed mid-call and then fails doesn't crash; a bug type still does. With the handler removed, the first test fails.
  • testDebugUnitTest: 522 pass. The 20 that fail are the existing Windows-only failures in EmulatedMacAnisetteTest / UnicornNoticeTest (File.renameTo over an existing file, and CRLF), unrelated.
  • By hand on the emulator, together with Run the account's loop on its own thread so iCloud calls stop queueing behind fetches #273: switching the theme and leaving Settings repeatedly no longer crashes.

🤖 Generated with Claude Code

Leaving Settings after a theme change rebuilds MapsActivity. The new one
restores a fresh account and closes the old one under PythonLock. The
old screen's fetch, queued on that lock, then ran on the closed account
("HttpSession has been closed"). Its subscription was already disposed,
so the error had nowhere to go, and RxJava's default handler killed the
process.

- PythonAppleService reads the account once it holds the lock: the
  current one if it was replaced meanwhile, nothing after a sign-out.
  HistoryViewActivity keeps an instance too, so this covers it as well.
- An UndeliverableException is logged instead of crashing. Anything else
  reaching RxJavaPlugins is a bug and still crashes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@parawanderer
parawanderer merged commit 748d118 into main Nov 21, 2026
4 checks passed
@parawanderer
parawanderer deleted the fix/fetch-on-a-replaced-account branch November 21, 2026 13:40

This branch was previously deployed

1 inactive deployment
Android Build — 2cb630ed Deployed Nov 21, 2026 by parawanderer via build #376
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