Skip to content

Conversation

@stefanosiano
Copy link
Member

@stefanosiano stefanosiano commented Oct 23, 2025

📜 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:

  • connectivityManager.getActiveNetwork()
  • connectivityManager.getNetworkCapabilities(activeNetwork)

The problem happens when the app goes to the foreground, as our AndroidConnectionStatusProvider onForeground is called, which runs updateCache in the background. At the same time, though, the ReplayIntegration runs updateCache on 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 updateCache are the culprit)

💚 How did you test it?

📝 Checklist

  • I added GH Issue ID & Linear ID
  • I added tests to verify the changes.
  • No new PII added or SDK only sends newly added PII if sendDefaultPII is enabled.
  • I updated the docs if needed.
  • I updated the wizard if needed.
  • Review from the native team if needed.
  • No breaking change or entry added to the changelog.
  • No breaking change for hybrid SDKs or communicated to hybrid SDKs.

🔮 Next steps

@stefanosiano stefanosiano marked this pull request as ready for review October 23, 2025 15:29
@github-actions
Copy link
Contributor

github-actions bot commented Oct 23, 2025

Performance metrics 🚀

  Plain With Sentry Diff
Startup time 385.49 ms 461.89 ms 76.40 ms
Size 1.58 MiB 2.12 MiB 551.70 KiB

Baseline results on branch: main

Startup times

Revision Plain With Sentry Diff
9fbb112 401.87 ms 515.87 ms 114.00 ms
b3d8889 371.84 ms 447.49 ms 75.65 ms
d217708 411.22 ms 430.86 ms 19.63 ms
27d7cf8 397.90 ms 498.65 ms 100.75 ms
fcec2f2 311.35 ms 384.94 ms 73.59 ms
ee747ae 358.21 ms 389.41 ms 31.20 ms
ee747ae 554.98 ms 611.50 ms 56.52 ms
b77456b 393.26 ms 441.10 ms 47.84 ms
27d7cf8 309.43 ms 364.27 ms 54.85 ms
b3d8889 371.33 ms 426.24 ms 54.92 ms

App size

Revision Plain With Sentry Diff
9fbb112 1.58 MiB 2.11 MiB 539.18 KiB
b3d8889 1.58 MiB 2.10 MiB 535.07 KiB
d217708 1.58 MiB 2.10 MiB 532.97 KiB
27d7cf8 1.58 MiB 2.12 MiB 549.42 KiB
fcec2f2 1.58 MiB 2.12 MiB 551.51 KiB
ee747ae 1.58 MiB 2.10 MiB 530.95 KiB
ee747ae 1.58 MiB 2.10 MiB 530.95 KiB
b77456b 1.58 MiB 2.12 MiB 548.11 KiB
27d7cf8 1.58 MiB 2.12 MiB 549.42 KiB
b3d8889 1.58 MiB 2.10 MiB 535.07 KiB

Previous results on branch: stefanosiano/fix/anr-connection-status

Startup times

Revision Plain With Sentry Diff
f208591 320.37 ms 351.59 ms 31.22 ms
241e3d5 316.48 ms 362.29 ms 45.81 ms

App size

Revision Plain With Sentry Diff
f208591 1.58 MiB 2.12 MiB 549.41 KiB
241e3d5 1.58 MiB 2.12 MiB 549.40 KiB

stefanosiano and others added 2 commits October 23, 2025 17:56
avoid concurrent cache updates
@cursor
Copy link

cursor bot commented Oct 23, 2025

Bug: Cache Update Lock Exception Handling

The isUpdatingCache flag might not reset if an exception occurs during the cache update, such as when acquiring the lock. This can permanently block all future connection status cache updates.

Fix in Cursor Fix in Web

avoid concurrent cache updates
cursor[bot]

This comment was marked as outdated.

avoid concurrent cache updates
cursor[bot]

This comment was marked as outdated.

@getsentry getsentry deleted a comment from cursor bot Nov 4, 2025
@getsentry getsentry deleted a comment from cursor bot Nov 4, 2025
@getsentry getsentry deleted a comment from cursor bot Nov 4, 2025
@getsentry getsentry deleted a comment from cursor bot Nov 4, 2025
@getsentry getsentry deleted a comment from cursor bot Nov 4, 2025
@getsentry getsentry deleted a comment from cursor bot Nov 4, 2025
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.

3 participants