Repository navigation
Conversation
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Want reviews to match your repository better? Bugbot Learning can learn team-specific rules from PR activity. A team admin can enable Learning in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit dd38ca1. Configure here.
| } | ||
| ensureNetworkCallbackRegistered(); | ||
| //noinspection Convert2MethodRef | ||
| submitSafe(() -> ensureNetworkCallbackRegistered()); |
There was a problem hiding this comment.
Background unregister races with async register
Medium Severity
addConnectionStatusObserver now queues ensureNetworkCallbackRegistered on the executor instead of registering on the caller. onBackground still returns immediately when networkCallback is null, without taking registrationLock or enqueueing unregister. networkCallback is only set after both binder registrations finish, and those calls are the slow path this change is removing from init. If the app backgrounds while that work is queued or in progress, unregister is skipped and the network and telephony callbacks stay registered in the background until a later foreground-then-background cycle.
Additional Locations (1)
Triggered by project rule: AGENTS.md
Reviewed by Cursor Bugbot for commit dd38ca1. Configure here.
|
@lazerg - Thanks a bunch for this and for digging into #6509 so quickly. Your diagnosis was spot on, but we've decided to close this in favor of #6537. It builds on the same core fix as yours but goes further for a few related paths that could still block the main thread:
You'll be credited as a co-author when it's merged. Thanks again for the contribution, it's really appreciated! 🙏 |


📜 Description
AndroidConnectionStatusProviderregistered the network callback and, since #6146, the telephony listener while holdinglock. Both are binder calls.addConnectionStatusObserverandupdateCacheneed the same lock, soSentryAndroid.initon the main thread (throughReplayIntegration.register) waited forregisterTelephonyCallbackto come back.Registering and unregistering now use a separate
registrationLock.lockstill guards the observers and the cache, and it is no longer held across those calls.registrationLockis always taken beforelock, never while holding it.addConnectionStatusObserveralso submits the registration to the executor instead of running it on the caller's thread. Otherwise the main thread could still wait onregistrationLockwhile the executor is insideregisterNetworkCallback.💡 Motivation and Context
SentryAndroid.initblocks main thread onAndroidConnectionStatusProviderlock held acrossregisterTelephonyCallbackbinder call (8.60.0+) #6509💚 How did you test it?
Added a unit test that adds an observer from a second thread while
registerDefaultNetworkCallbackand thenregisterTelephonyCallbackare running. It fails onmainbecause the second thread stays blocked on the lock, and passes with this change.:sentry-android-core:testReleaseUnitTestpasses.📝 Checklist
sendDefaultPIIis enabled.🔮 Next steps