alexkendall / react-native-bluetooth-cross-platform

Cross-Platform Bluetooth & WiFi React Native Module. Powered by underdark http://underdark.io/.
179 stars 35 forks source link

Improving iOS concurrency in eventHandler logic #48

Closed ryanpatk closed 5 years ago

ryanpatk commented 5 years ago

Hello @alexkendall !

I have been using your library for a few months now and it has been awesome! 🎉Has allowed me to build an app that would've been unthinkable otherwise.

Unfortunately, I have noticed that there are some app crashes that appear to stem from the library. I'm not an expert on this source code nor an iOS developer, but after some debugging it appears that there were issues with multiple functions manipulating the links and nearbyUsers arrays simultaneously.

The errors were as below:

screen shot 2018-08-31 at 2 30 05 pm screen shot 2018-08-31 at 4 13 25 pm

These crashes occurred when I had multiple devices connected, and started toggling some of them in and out of airplane mode to simulate disconnection and reconnection.

I fixed the issue used a synchronous dispatch queue and looping backwards instead of forwards to protect the links and nearbyUsers array indices.

I went ahead and forked the repo to make changes and everything looks good on my end now. I just wanted to propose this code to you in case you feel it is an improvement to the codebase.

Also, if you see anything that I've done that doesn't seem right feel free to let me know. Thanks!