René's URL Explorer Experiment


Title: fix(android): Don't block callers on network status registration by 0xadam-brown · Pull Request #6537 · getsentry/sentry-java · GitHub

Open Graph Title: fix(android): Don't block callers on network status registration by 0xadam-brown · Pull Request #6537 · getsentry/sentry-java

X Title: fix(android): Don't block callers on network status registration by 0xadam-brown · Pull Request #6537 · getsentry/sentry-java

Description: This PR's diff looks more involved than it actually is. Most of the changes are new docs and tests. Prod changes are limited to introducing a new ConnectionSnapshot that combines a number of previously distinct fields + minor revisions in bookkeeping needed to update that snapshot vs the previous fields. 📜 Description AndroidConnectionStatusProvider no longer makes callers wait while it registers its network and telephony callbacks with system services. That's good because one of those callers is Sentry.init. The problem Before this change, AndroidConnectionStatusProvider used one lock to guard three code paths: callback registration, connection cache refreshes, and adding or removing observers. The SDK executor held that lock across ConnectivityManager.registerDefaultNetworkCallback and, on API 31+, TelephonyManager.registerTelephonyCallback. Both are calls into system services that can occasionally block for seconds. The main thread waited on the same lock in two places: Session Replay adding its observer during Sentry.init. Every captured event reading the connection type or status. If the system service registrations took a while, the main thread would stall. Scenario (1) in particular could lead to ANRs during app startup. Oof. A road not taken Any fix has to isolate the slow part (registration) so that the main thread can return quickly when reading cached network info or adding observers. The narrowest approach would be to give registration its own lock and keep a second lock for the cache and observers. But a refresh would then either hold the cache lock while querying Android, making readers wait on that query, or need a version counter that every write must remember to update. Even worse, two locks would need to document order they're taken in to avoid deadlock, which would be easy to get wrong. That's^^ the approach my clanker initially implemented (see commit 1). But there's a better way... A better approach (and the one this PR implements) The approach I ultimately landed on was to avoid having the main thread hold a lock entirely, and instead rely on atomically publishing cached network info (see commit 2). I did so by introducing a new ConnectionSnapshot class, which is immutable and can be safely shared across threads. I stored observers in copy-on-write lists rather than having them be explicitly locked, and I confined registration to the the SDK executor (it's still defensively guarded by its own lock). Callers that need to access cached network info or register observers can now return quickly. Either of approach would have allowed as much, of course, but the benefit of introducing the snapshot it that it also: lets us consolidate a lot of related state that the provider previously had to handle separately avoids the pain of managing (yet another) lock lays the groundwork for future PRs that confine refreshes to the SDK executor and let snapshots tell a lost network from capabilities that are simply unknown. Bonus points It took me a while to figure out exactly what policies AndroidConnectionStatusProvider implemented, and so I've updated the docs to make that clearer. I've also renamed a few things that threw me for a loop (eg, isConnected -> onAvailableForwarded, as it's actually a flag to make sure the provider only forwards onAvailable calls to clients at most once, and shouldn't be used to determine whether the network is currently connected). Reviewing by commit In case it's helpful, I got my clanker to break up this work into coherent commits. Personally, I'd limit myself to reviewing the final diff, but up to you. Commit Change 1. fix: Don't block callers on connection status registration The core fix and its concurrency tests. The cache still uses a lock plus a version counter here. 2. ref: Hold the connection cache in an immutable snapshot Replaces that lock and counter. It also fixes two races: onAvailable wrote the network without the lock, and the status lookup read the capabilities twice. 3. fix: Don't register connection callbacks again after close Fixes a leak introduced by commit 1's asynchronous registration. 4. ref: Rename isConnected to onAvailableForwarded Rename only. 5. `fix: Build the connection cache debug log only when debug logging is on 6. docs: Document the threading and exception policies Javadoc and field order. No behavior change. 7. test: Improve the concurrency tests Risks and costs Performance and memory: Negligible. One small snapshot object per network event or cache refresh. Copy-on-write lists, which only change at init and close; notifying doesn't allocate. One extra executor task per app foreground or background switch. Crash risk: No new risks, and one existing risk removed. The new copy-on-write lists eliminate a latent ConcurrentModificationException, which could happen under the previous approach when an observer removed itself on the notifying thread. Leaks: No new risks. The closed flag covers the one potential leak asynchronous registration would otherwise add. Two leaks predate this PR and are unchanged: If the executor drops the close task, the system callbacks stay registered. An observer added after close() is never cleared. Behavior changes: None visible to users under normal operation. In a rare race after the app returns to the foreground, a network breadcrumb could be duplicated or missed. No crash or data loss. Closing the SDK while registration is still pending now skips the registration entirely. Nothing is left registered either way. 💡 Motivation and Context App-start ANRs reported in #6509, a regression from #6146 (8.60.0 through 8.63.0). resolves: #6509 resolves: JAVA-828 💚 How did you test it? Concurrency tests Unit tests Had my clanker manually check via the sample app that the approach here fixes things. 📝 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. Public API changes reviewed by another Mobile SDK team member or implemented according to the develop docs spec. 🔮 Next steps Hybrid SDKs: once released, ask them to upgrade, and add a known-issue note to 8.60.0 through 8.63.0. Possible follow-ups for AndroidConnectionStatusProvider, in separate PRs: (Existing issues I noticed while implementing the current PR . Out of scope for now.) Stale-cache reads still query the ConnectivityManager on the caller's thread. A snapshot without capabilities falls back to that query on every read. We don't extend the cache lifetime for network capability changes that don't affect the status. Concurrent stale reads can query for network info more than once. Registration state could also become an explicit state model. Fix the potential (and preexisting) leaks mentioned under "Risks and Costs".

Open Graph Description: This PR's diff looks more involved than it actually is. Most of the changes are new docs and tests. Prod changes are limited to introducing a new ConnectionSnapshot that combines a number of pr...

X Description: This PR's diff looks more involved than it actually is. Most of the changes are new docs and tests. Prod changes are limited to introducing a new ConnectionSnapshot that combines a number o...

Opengraph URL: https://github.com/getsentry/sentry-java/pull/6537

X: @github

direct link

Domain: github.com

IPv4 address: 140.82.114.4

react-profiling0
react-import-mapreact,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322
route-pattern/:user_id/:repository/pull/:id/files(.:format)
route-controllerpull_requests
route-actionfiles
fetch-noncev2:c9979a5a-3595-23bc-4d05-458e0fe0e5d8
current-catalog-service-hashae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b
request-id952E:2CE84F:828689:B88353:6B0452EF
html-safe-nonce97d89c4e4749ed1012dfcdbb80c6611b2d259f40cf49ee11d0158330d6023905
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5NTJFOjJDRTg0Rjo4Mjg2ODk6Qjg4MzUzOjZCMDQ1MkVGIiwidmlzaXRvcl9pZCI6IjcwMDMwNzQ3NzA2OTkwNDc2NjMiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ==
visitor-hmac7efd4811f49c7b8a931aaa630fcaf4bdbfd6543cfb6cd470f6c8750c2944d76f
hovercard-subject-tagpull_request:5239311308
github-keyboard-shortcutsrepository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///pull_requests/show/files
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/getsentry/sentry-java/pull/6537/files
twitter:imagehttps://avatars.githubusercontent.com/u/281682121?s=400&v=4
twitter:cardsummary_large_image
og:imagehttps://avatars.githubusercontent.com/u/281682121?s=400&v=4
og:image:altThis PR's diff looks more involved than it actually is. Most of the changes are new docs and tests. Prod changes are limited to introducing a new ConnectionSnapshot that combines a number of pr...
og:site_nameGitHub
og:typeobject
hostnamegithub.com
expected-hostnamegithub.com
None910ca0e260cfec6aff11407d8dc6a0d3a4cd381a2ec9ada56627b063426892a0
turbo-cache-controlno-preview
diff-viewunified
go-importgithub.com/getsentry/sentry-java git https://github.com/getsentry/sentry-java.git
octolytics-dimension-user_id1396951
octolytics-dimension-user_logingetsentry
octolytics-dimension-repository_id3368190
octolytics-dimension-repository_nwogetsentry/sentry-java
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id3368190
octolytics-dimension-repository_network_root_nwogetsentry/sentry-java
turbo-body-classeslogged-out env-production page-responsive full-width
disable-turbotrue
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
releasee086f9b7e88322eb2b41885a6ad425b215737fa5
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://github.com/getsentry/sentry-java/pull/6537/files#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fgetsentry%2Fsentry-java%2Fpull%2F6537%2Ffiles
GitHubRepository hosting, code review, and collaborationhttps://github.com/platform
CopilotAI coding agent for tasks, projects, and automated workhttps://github.com/features/copilot
ActionsCI/CD and automationhttps://github.com/features/actions
Code QualityQuality analysis, fixes, and enforcementhttps://github.com/features/code-quality
CodespacesCloud development environmentshttps://github.com/features/codespaces
Code SecurityVulnerability detection and remediationhttps://github.com/security/advanced-security/code-security
Secret ProtectionSecret scanning and leak preventionhttps://github.com/security/advanced-security/secret-protection
All Featureshttps://github.com/features
Documentationhttps://docs.github.com/en
Traininghttps://learn.github.com/skills
Certificationshttps://learn.github.com/credentials
Build with Copilothttps://github.com/features/ai
Customize Copilothttps://docs.github.com/en/copilot/how-tos/copilot-on-github/customize-copilot/customize-copilot-overview
Integrationshttps://github.com/marketplace
Trending reposhttps://github.com/trending
GitHub Sponsorshttps://github.com/open-source/sponsors
Developer articleshttps://github.com/resources/articles
ChangelogYour source for the latest features, improvements, and fixes across GitHub products, all in one place.https://github.blog/changelog/
Enterpriseshttps://github.com/enterprise
Teamhttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
See all industrieshttps://github.com/solutions/industry
Why GitHubhttps://github.com/why-github
Customer Storieshttps://github.com/customer-stories
Business insightshttps://github.com/solutions/executive-insights
Trust Centerhttps://github.com/trust-center
GitHub Advanced SecurityEnterprise-grade code securityhttps://github.com/security/advanced-security
Copilot for businessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/enterprise/premium-support
Documentationhttps://docs.github.com/en
Resource centerhttps://github.com/resources
Bloghttps://github.blog/
Events & webinarshttps://github.com/resources/events
Community Forumhttps://github.com/orgs/community/discussions
Customer Storieshttps://github.com/customer-stories
Integrationshttps://github.com/marketplace
Customer supporthttps://help.github.com/
Traininghttps://learn.github.com/skills
GitHub Statushttps://www.githubstatus.com/
Abouthttps://github.com/about
Partnershttps://github.com/partners
Changeloghttps://github.blog/changelog/
GitHub UniverseThe event for developers, by developers — talks, workshops, and what’s next for GitHub.https://githubuniverse.com/
Pricinghttps://github.com/pricing
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fgetsentry%2Fsentry-java%2Fpull%2F6537%2Ffiles
Sign uphttps://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fpull_requests%2Fshow%2Ffiles&source=header-repo&source_repo=getsentry%2Fsentry-java
Reloadhttps://github.com/getsentry/sentry-java/pull/6537/files
Reloadhttps://github.com/getsentry/sentry-java/pull/6537/files
Reloadhttps://github.com/getsentry/sentry-java/pull/6537/files
getsentryhttps://github.com/getsentry
sentry-javahttps://github.com/getsentry/sentry-java
Codehttps://github.com/getsentry/sentry-java
Issues266 (266)https://github.com/getsentry/sentry-java/issues
Pull requests58 (58)https://github.com/getsentry/sentry-java/pulls
Discussionshttps://github.com/getsentry/sentry-java/discussions
Actionshttps://github.com/getsentry/sentry-java/actions
Projectshttps://github.com/getsentry/sentry-java/projects
Security and quality2 (2)https://github.com/getsentry/sentry-java/security
Insightshttps://github.com/getsentry/sentry-java/insights
Sign up for GitHub https://github.com/signup?return_to=%2Fgetsentry%2Fsentry-java%2Fissues%2Fnew%2Fchoose
terms of servicehttps://docs.github.com/terms
privacy statementhttps://docs.github.com/privacy
Sign inhttps://github.com/login?return_to=%2Fgetsentry%2Fsentry-java%2Fissues%2Fnew%2Fchoose
0xadam-brownhttps://github.com/0xadam-brown
mainhttps://github.com/getsentry/sentry-java/tree/main
fix/dont-block-main-on-connectivity-registrationhttps://github.com/getsentry/sentry-java/tree/fix/dont-block-main-on-connectivity-registration
Conversation 8 https://github.com/getsentry/sentry-java/pull/6537
Commits 10 https://github.com/getsentry/sentry-java/pull/6537/commits
Checks 45 https://github.com/getsentry/sentry-java/pull/6537/checks
Files changed https://github.com/getsentry/sentry-java/pull/6537/files
Please reload this pagehttps://github.com/getsentry/sentry-java/pull/6537/files
fix(android): Don't block callers on network status registration https://github.com/getsentry/sentry-java/pull/6537/files#top
Show all changes 10 commits https://github.com/getsentry/sentry-java/pull/6537/files
d2f231b fix(android): Don't block callers on connection status registration 0xadam-brown Nov 9, 2026 https://github.com/getsentry/sentry-java/pull/6537/commits/d2f231b3350b602d0aec48140aec4981cba5431a
51a88a9 ref(android): Hold the connection cache in an immutable snapshot 0xadam-brown Nov 9, 2026 https://github.com/getsentry/sentry-java/pull/6537/commits/51a88a903f41ddc7da61d4e5e75fea275ed0a461
098064c fix(android): Don't register connection callbacks again after close 0xadam-brown Nov 9, 2026 https://github.com/getsentry/sentry-java/pull/6537/commits/098064c37649d1107aec9f9b9dbbd93e1cd254e4
31aba53 ref(android): Rename isConnected to onAvailableForwarded 0xadam-brown Nov 10, 2026 https://github.com/getsentry/sentry-java/pull/6537/commits/31aba53070be1aae3bd8f91f1352e6ea375eb206
1f56d96 fix(android): Build the connection cache debug log only when debug lo… 0xadam-brown Nov 10, 2026 https://github.com/getsentry/sentry-java/pull/6537/commits/1f56d967823b932e8e2a3a8d5e7bd1316920372c
f804ac1 docs(android): Document AndroidConnectionStatusProvider's threading a… 0xadam-brown Nov 10, 2026 https://github.com/getsentry/sentry-java/pull/6537/commits/f804ac1e0096a320c340c89eee86a3d5eadea87c
f2a7096 test(android): Tighten connection status provider concurrency tests 0xadam-brown Nov 10, 2026 https://github.com/getsentry/sentry-java/pull/6537/commits/f2a7096490b3754803bd9bf0f1e39e27f59fb80a
9faedfb changelog 0xadam-brown Nov 10, 2026 https://github.com/getsentry/sentry-java/pull/6537/commits/9faedfbf90df4443582978131fb2991c6ffe8f02
43d74a6 fix(android): ADDRESS PR COMMENT: Keep a cache refresh's result when … 0xadam-brown Nov 10, 2026 https://github.com/getsentry/sentry-java/pull/6537/commits/43d74a6280bd44a83febcbd02ee47d4c3300f5ca
5c30e7f ref(android): Add ConnectionSnapshot.toString for debugging 0xadam-brown Nov 10, 2026 https://github.com/getsentry/sentry-java/pull/6537/commits/5c30e7f76c8b9cdd82c7b6b2fc3b7c4bbcca0f78
Clear filters https://github.com/getsentry/sentry-java/pull/6537/files
Please reload this pagehttps://github.com/getsentry/sentry-java/pull/6537/files
Please reload this pagehttps://github.com/getsentry/sentry-java/pull/6537/files
CHANGELOG.md https://github.com/getsentry/sentry-java/pull/6537/files#diff-06572a96a58dc510037d5efa622f9bec8519bc1beab13c9f251e97e657a9d4ed
AndroidConnectionStatusProvider.java https://github.com/getsentry/sentry-java/pull/6537/files#diff-aadb2b267f52db6cae59f8995d3a5c08b63578296e8835f1ed689a94f76f80d0
AndroidConnectionStatusProviderConcurrencyTest.kt https://github.com/getsentry/sentry-java/pull/6537/files#diff-d409165c886c59e0825355fee5b99877c42ea97d513ea5c85298cad802868cde
AndroidConnectionStatusProviderTest.kt https://github.com/getsentry/sentry-java/pull/6537/files#diff-f4592824a6307411e4c6322292cb06881a9558a6aaab7280f92ea577decb4a59
https://github.com/getsentry/sentry-java/blob/main/.github/CODEOWNERS#L1
CHANGELOG.mdhttps://github.com/getsentry/sentry-java/pull/6537/files#diff-06572a96a58dc510037d5efa622f9bec8519bc1beab13c9f251e97e657a9d4ed
View file https://github.com/getsentry/sentry-java/blob/5c30e7f76c8b9cdd82c7b6b2fc3b7c4bbcca0f78/CHANGELOG.md
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/getsentry/sentry-java/pull/6537/{{ revealButtonHref }}
https://github.com/getsentry/sentry-java/pull/6537/files#diff-06572a96a58dc510037d5efa622f9bec8519bc1beab13c9f251e97e657a9d4ed
https://github.com/getsentry/sentry-java/pull/6537/files#diff-06572a96a58dc510037d5efa622f9bec8519bc1beab13c9f251e97e657a9d4ed
Please reload this pagehttps://github.com/getsentry/sentry-java/pull/6537/files
Please reload this pagehttps://github.com/getsentry/sentry-java/pull/6537/files
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Response headers:
Servergithub.com
Content-Typetext/html; charset=utf-8
Cache-Controlno-cache

Viewport: width=device-width


URLs of crawlers that visited me.