Skip to content

fix(location): update ios location implementation to handle thread issues#71

Open
CoryWritesCode wants to merge 1 commit into
douglasjunior:masterfrom
CoryWritesCode:master
Open

fix(location): update ios location implementation to handle thread issues#71
CoryWritesCode wants to merge 1 commit into
douglasjunior:masterfrom
CoryWritesCode:master

Conversation

@CoryWritesCode
Copy link
Copy Markdown
Contributor

We've been getting a steady stream of EXC_BAD_ACCESS crashes in LocationModuleImpl showing up on _dispatch_worker_thread2. Turns out CLLocationManager is thread-affine — you have to talk to it on the thread you created it on. getCurrentPosition: creates the manager on main, but locationManagerDidChangeAuthorization: was hopping onto a background queue and poking the manager from there. iOS 14+ really doesn't like that.

The original reason for the background hop was fine: +locationServicesEnabled isn't supposed to run on main because it can block. The fix just took too much stuff off-main along for the ride.

Fix

  • locationManagerDidChangeAuthorization: now grabs authorizationStatus on the delegate thread, hops to background only for +locationServicesEnabled, then comes back to main before touching the manager. Moved the actual handling into a new handleAuthorizationStatus:servicesEnabled: helper.
  • clearReferences bounces back to main if it's called off-main, and nils out the delegate before stopUpdatingLocation so a late callback can't land on a dead promise.
  • Added the mReject != nil check in the two spots it was missing.
  • Turned the file-scope statics (mTimer / mLocationManager / mResolve / mReject / mTimeout) into ivars. No behavior change, just less scary.
  • isAuthorized returns NO if the manager is nil instead of messaging nil.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant