question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

iOS: Many crashes due to lack of thread-safety

See original GitHub issue

Please use Discussion board if you want get some help out of it. Please report issue if there is a bug.

Version of react-native-iap

8.0.8

Version of react-native

0.67.4

Platforms you faced the error (IOS or Android or both?)

iOS

Expected behavior

No crashing

Actual behavior

Random crashes with stack trace like this:

Crashed: com.facebook.react.RNIapIosQueue
EXC_BAD_ACCESS KERN_INVALID_ADDRESS 0x0000000000000000

<compiler-generated> - Line 388412 RNIapIos.addPromise(forKey:resolve:reject:) + 388412
RNIapIos.swift - Line 165 RNIapIos.getItems(_:resolve:reject:) + 165
<compiler-generated> - Line 391604 @objc RNIapIos.getItems(_:resolve:reject:) + 391604

Tested environment (Emulator? Real Device?)

Real device

Steps to reproduce the behavior

This is caused by non-thread-safe access to the dictionary promisesByKey. A serial queue was added to protect some of these accesses but not all. IMHO a better way to protect this is by adding dispatch directly inside of addPromise, resolvePromises & rejectPromises.

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:4
  • Comments:9 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
phillip-kiccommented, Aug 15, 2022

I believe we may be having issues related to this as well. We are seeing crashes on release builds which is preventing us from upgrading in production.

This is occurring when fetching subscription products. The Apple Docs warn that the SKProductsRequestDelegate may not return on a specific thread so feels likely that lack of thread-safety is the issue here?

Stack trace

Hardware Model:     iPhone13,4
Role:               Foreground
OS Version:         iOS 15.5
Exception Type:     EXC_BAD_ACCESS 
Exception Subtype:  KERN_INVALID_ADDRESS


EXC_BAD_ACCESS: Attempted to dereference garbage pointer 0x8000000000000028.

0  App Name                specialized __RawDictionaryStorage.find<A>(_:) (<compiler-generated>)
1  App Name                specialized Dictionary._Variant.removeValue(forKey:) (<compiler-generated>)
2  App Name                specialized Dictionary.removeValue(forKey:) (<compiler-generated>)
3  App Name                RNIapIos.productsRequest(_:didReceive:) (RNIapIos.swift:451:5)
4  App Name                @objc RNIapIos.productsRequest(_:didReceive:) (<compiler-generated>)
5  StoreKit                __27-[SKProductsRequest _start]_block_invoke_2
6  libdispatch.dylib       _dispatch_call_block_and_release
7  libdispatch.dylib       _dispatch_client_callout
8  libdispatch.dylib       _dispatch_queue_override_invoke
9  libdispatch.dylib       _dispatch_root_queue_drain
10 libdispatch.dylib       _dispatch_worker_thread2
11 libsystem_pthread.dylib _pthread_wqthread
12 libsystem_pthread.dylib start_wqthread
0reactions
andresesfmcommented, Sep 26, 2022

Please create a new ticket if this is still happening on 11.x.x. Also please use the new Bug report template. There’s simply not enough information here to try to reproduce. I’ll be happy to look at it.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Xcode 11 dictionary doesn't like concurrent access on iOS
my app that worked fine under Xcode 10 crashes under Xcode 11 (beta 3). ... It's simply not safe to share unprotected mutable...
Read more >
David Kilzer
Thread safety crashes tend to manifest as multiple signatures that occur in the same area of code, usually reading or writing the same...
Read more >
Concurrency & Thread Safety in Swift | by Sean Lin | Cubo AI
While multithreading is powerful, it comes with great complexity and also introduces two common issues. One is race conditions and the other is ......
Read more >
What does it mean for something to be thread safe in iOS?
Thread safe code can be safely called from multiple threads or concurrent tasks without causing any problems (data corruption, crashing, etc).
Read more >
Thread-Safe Class Design
But if two threads set the image at the same time, it's likely that your app will simply crash, because the currently set...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found