-
-
Notifications
You must be signed in to change notification settings - Fork 458
[ANR] Update Connection Status cache in the background #4832
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
…d, so lock is not acquired indefinitely
Bug: Unprotected Cache Update Causes Data RaceThe Additional Locations (1) |
Bug: Race Condition in Network Capability CacheThe |
Performance metrics 🚀
|
| Revision | Plain | With Sentry | Diff |
|---|---|---|---|
| d364ace | 382.77 ms | 443.21 ms | 60.44 ms |
| 3998a95 | 415.94 ms | 478.54 ms | 62.60 ms |
| 806307f | 357.85 ms | 424.64 ms | 66.79 ms |
| ee747ae | 357.79 ms | 421.84 ms | 64.05 ms |
| d217708 | 355.34 ms | 381.39 ms | 26.05 ms |
| ee747ae | 396.82 ms | 441.67 ms | 44.86 ms |
| 604a261 | 380.65 ms | 451.27 ms | 70.62 ms |
| 3699cd5 | 423.60 ms | 495.52 ms | 71.92 ms |
| b3d8889 | 371.84 ms | 447.49 ms | 75.65 ms |
| d5a29b6 | 298.62 ms | 391.78 ms | 93.16 ms |
App size
| Revision | Plain | With Sentry | Diff |
|---|---|---|---|
| d364ace | 1.58 MiB | 2.11 MiB | 539.75 KiB |
| 3998a95 | 1.58 MiB | 2.10 MiB | 532.96 KiB |
| 806307f | 1.58 MiB | 2.10 MiB | 533.42 KiB |
| ee747ae | 1.58 MiB | 2.10 MiB | 530.95 KiB |
| d217708 | 1.58 MiB | 2.10 MiB | 532.97 KiB |
| ee747ae | 1.58 MiB | 2.10 MiB | 530.95 KiB |
| 604a261 | 1.58 MiB | 2.10 MiB | 533.42 KiB |
| 3699cd5 | 1.58 MiB | 2.10 MiB | 533.45 KiB |
| b3d8889 | 1.58 MiB | 2.10 MiB | 535.07 KiB |
| d5a29b6 | 1.58 MiB | 2.12 MiB | 549.37 KiB |
avoid concurrent cache updates
Bug: Cache Update Timing Causes Stale DataThe |
Bug: Cache Update Race ConditionA race condition allows |
Bug: Cache Update Timing and Error HandlingThe Additional Locations (1) |
avoid concurrent cache updates
avoid concurrent cache updates
| options.getLogger().log(SentryLevel.WARNING, "Failed to update connection status cache", t); | ||
| } catch (Throwable t) { | ||
| options.getLogger().log(SentryLevel.WARNING, "Failed to update connection status cache", t); | ||
| try (final @NotNull ISentryLifecycleToken ignored = lock.acquire()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bug: Cache Update Timing Causes Stale Data
updateCache() now clears the cache and updates its timestamp before asynchronously fetching network capabilities. This creates a race condition where immediate reads (e.g., in onForeground(), getConnectionStatus()) get stale or null data, and isCacheValid() incorrectly reports the cleared cache as valid.
📜 Description
AndroidConnectionStatusProvider cache is now updated in the background, so lock is not acquired indefinitely
💡 Motivation and Context
There are a lot of ANRs in our Play console and in our own SDKCD tool, that report ANRs due to a lock in
AndroidConnectionStatusProvider.We were doing some IPC calls inside the lock, which may cause the ANR:
The problem happens when the app goes to the foreground, as our
AndroidConnectionStatusProvideronForegroundis called, which runsupdateCachein the background. At the same time, though, theReplayIntegrationrunsupdateCacheon the main thread at the same moment (when the app goes to the foreground).The ANR happens because of the mainThread awaiting the lock (it shouldn't happen, but maybe the IPC calls done in
updateCacheare the culprit)💚 How did you test it?
📝 Checklist
sendDefaultPIIis enabled.🔮 Next steps