Commit e130706
fix(android,ios): add thread safety to listener operations (#3152)
## Summary
- Android: wrap listener add/remove/iterate in `synchronized` blocks to
prevent `ConcurrentModificationException`
- iOS: add warning logs when `HybridRnIap` is deallocated during
purchase/error listener callbacks for better diagnostics
## Changes
### Android (`HybridRnIap.kt`)
- `addPurchaseUpdatedListener`, `removePurchaseUpdatedListener`,
`addPurchaseErrorListener`, `removePurchaseErrorListener` now use
`synchronized` blocks
- `sendPurchaseUpdate` and `sendPurchaseError` iterate listeners within
`synchronized` blocks
- Prevents race conditions when listeners are modified from one thread
while being iterated on another
### iOS (`HybridRnIap.swift`)
- Added `RnIapLog.warn` messages when `self` is deallocated (`nil`) in
OpenIAP purchase and error listener callbacks
- Helps diagnose cases where purchase events are dropped due to
`HybridRnIap` lifecycle issues (related to #3150)
## Context
Investigating #3150 (purchases not being notified) revealed a potential
thread safety issue in listener management on Android, and a diagnostics
gap on iOS where purchase events could be silently dropped if the native
module was deallocated.
## Test plan
- [x] `yarn typecheck` passes
- [x] `yarn lint` passes
- [x] Pre-commit hooks pass
🤖 Generated with [Claude Code](https://claude.ai/code)
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit
* **Bug Fixes**
* Improved thread-safety for in-app purchase listener registration and
event dispatch on Android to prevent race conditions.
* Added guards and clearer logging for in-app purchase event handling on
iOS so events are dropped with warnings if the handler is no longer
available.
* **Chores**
* Increased CI/CD deployment validation timeout to allow longer-running
checks.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
---------
Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>1 parent 6343b15 commit e130706
File tree
3 files changed
+35
-22
lines changed- .github/workflows
- android/src/main/java/com/margelo/nitro/iap
- ios
3 files changed
+35
-22
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
62 | 62 | | |
63 | 63 | | |
64 | 64 | | |
65 | | - | |
| 65 | + | |
66 | 66 | | |
67 | 67 | | |
68 | 68 | | |
| |||
Lines changed: 22 additions & 18 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
255 | 255 | | |
256 | 256 | | |
257 | 257 | | |
258 | | - | |
259 | | - | |
| 258 | + | |
| 259 | + | |
260 | 260 | | |
261 | 261 | | |
262 | 262 | | |
| |||
731 | 731 | | |
732 | 732 | | |
733 | 733 | | |
734 | | - | |
| 734 | + | |
| 735 | + | |
| 736 | + | |
735 | 737 | | |
736 | | - | |
| 738 | + | |
737 | 739 | | |
738 | | - | |
| 740 | + | |
| 741 | + | |
| 742 | + | |
739 | 743 | | |
740 | | - | |
| 744 | + | |
741 | 745 | | |
742 | | - | |
743 | | - | |
| 746 | + | |
| 747 | + | |
| 748 | + | |
744 | 749 | | |
745 | | - | |
| 750 | + | |
746 | 751 | | |
747 | | - | |
748 | | - | |
| 752 | + | |
| 753 | + | |
| 754 | + | |
749 | 755 | | |
750 | 756 | | |
751 | 757 | | |
| |||
773 | 779 | | |
774 | 780 | | |
775 | 781 | | |
776 | | - | |
777 | | - | |
778 | | - | |
| 782 | + | |
| 783 | + | |
779 | 784 | | |
780 | | - | |
| 785 | + | |
781 | 786 | | |
782 | 787 | | |
783 | 788 | | |
| |||
786 | 791 | | |
787 | 792 | | |
788 | 793 | | |
789 | | - | |
790 | | - | |
791 | | - | |
| 794 | + | |
| 795 | + | |
792 | 796 | | |
793 | 797 | | |
794 | 798 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
899 | 899 | | |
900 | 900 | | |
901 | 901 | | |
902 | | - | |
| 902 | + | |
| 903 | + | |
| 904 | + | |
| 905 | + | |
903 | 906 | | |
904 | 907 | | |
905 | 908 | | |
| |||
917 | 920 | | |
918 | 921 | | |
919 | 922 | | |
920 | | - | |
| 923 | + | |
| 924 | + | |
| 925 | + | |
| 926 | + | |
921 | 927 | | |
922 | 928 | | |
923 | 929 | | |
| |||
935 | 941 | | |
936 | 942 | | |
937 | 943 | | |
938 | | - | |
| 944 | + | |
| 945 | + | |
| 946 | + | |
| 947 | + | |
939 | 948 | | |
940 | 949 | | |
941 | 950 | | |
| |||
0 commit comments