Skip to content

Conversation

joshdholtz
Copy link
Member

@joshdholtz joshdholtz commented Sep 3, 2025

Motivation

Improve thread safety of setting preferred locale

Description

Make the variable @Volatile

- Replace @get:Synchronized with @volatile field for atomic reads/writes
- Use minimal synchronized block only for the two-step update operation
- Network calls happen outside synchronized block for better performance
- Maintains thread safety while minimizing lock contention

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
@joshdholtz joshdholtz marked this pull request as ready for review September 3, 2025 15:01
Copy link
Contributor

@tonidero tonidero left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should be safe enough! Didn't see any of issues with it 👍

@joshdholtz joshdholtz changed the title Use @Volatile + synchronized block for optimal thread safety Improve thread safety of setting paywalls preferred locale Sep 3, 2025
Copy link

codecov bot commented Sep 3, 2025

Codecov Report

❌ Patch coverage is 0% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 78.09%. Comparing base (354e30d) to head (fb3dc0f).
⚠️ Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
.../com/revenuecat/purchases/PurchasesOrchestrator.kt 0.00% 4 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2655      +/-   ##
==========================================
- Coverage   78.10%   78.09%   -0.02%     
==========================================
  Files         306      306              
  Lines       11482    11484       +2     
  Branches     1590     1590              
==========================================
  Hits         8968     8968              
- Misses       1817     1819       +2     
  Partials      697      697              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@joshdholtz joshdholtz added this pull request to the merge queue Sep 3, 2025
Merged via the queue into main with commit 9d23856 Sep 3, 2025
21 checks passed
@joshdholtz joshdholtz deleted the fix-preferred-locale-atomicness branch September 3, 2025 15:40
github-merge-queue bot pushed a commit that referenced this pull request Sep 3, 2025
**This is an automatic release.**

## RevenueCat SDK
### ✨ New Features
* Add preferred UI locale override for RevenueCat UI components (#2620)
via Josh Holtz (@joshdholtz)

### 🔄 Other Changes
* Improve thread safety of setting paywalls preferred locale (#2655) via
Josh Holtz (@joshdholtz)
* Remove validation for no packages on paywalls (#2653) via Josh Holtz
(@joshdholtz)
* Video Component Models (dark code) (#2646) via Jacob Rakidzich
(@JZDesign)
* [EXTERNAL] docs: fixed a typo on documentation about
`Purchases.awaitPurchase` by @matteinn in #2593 (#2651) via Toni Rico
(@tonidero)
* Add warning with 9.x issues to all versions since 9.0.0 in CHANGELOG
(#2650) via Toni Rico (@tonidero)
* [AUTOMATIC][Paywalls V2] Updates paywall-preview-resources submodule
(#2647) via RevenueCat Git Bot (@RCGitBot)
* Delete CLAUDE.md (#2648) via Cesar de la Vega (@vegaro)
* MON-1193 flatten Transition JSON structure after chatting more
thoroughly with team (#2641) via Jacob Rakidzich (@JZDesign)

---------

Co-authored-by: revenuecat-ops <ops@revenuecat.com>
Co-authored-by: Josh Holtz <me@joshholtz.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants