Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Crash mapbox::sqlite::Exception authorisation denied on iOS with Data Protection enabled #6205

Closed
macteo opened this issue Aug 30, 2016 · 6 comments
Labels
crash iOS Mapbox Maps SDK for iOS offline

Comments

@macteo
Copy link

macteo commented Aug 30, 2016

Platform: iOS
Mapbox SDK version: 3.3.4

Steps to trigger behavior

  1. Integrate MapBox (through CocoaPods).
  2. Enable background location updates with CoreLocation.
  3. Enable Data Protection.
  4. Create a controller with a MGLMapView instance visible that appears as soon as you launch the app.

Expected behaviour

The app will be relaunched in background by the system as soon as a location update is available. The device can be locked and the data will be encrypted.
The app should be able to run anyway in background.

Actual behaviour

The app crashes as with a mapbox::sqlite::Exception authorization denied.
I suppose that it is caused by MapBox trying to access a sqlite database that is present but not accessible as Data Protection kicks in.

If you really need to be always able to access the database, you should consider to create the file with no file protection specifying FileProtectionType.none:

FileManager.default.createFile(atPath: path, contents: data, attributes: [FileAttributeKey.protectionKey.rawValue: FileProtectionType.none])

It would even better if you check if the file is available and use it only if the app is in foreground, so its content stays encrypted.

mapbox-crashlog.txt

@boundsj boundsj added bug iOS Mapbox Maps SDK for iOS labels Aug 30, 2016
@1ec5 1ec5 added offline crash and removed bug labels Aug 30, 2016
@1ec5
Copy link
Contributor

1ec5 commented Aug 30, 2016

The SQLite database is created in C++ code that the Objective-C code has no control over, but maybe we can set the attribute on the directory containing it like we do for excluding the database from backups.

@jfirebaugh
Copy link
Contributor

Previously: #4841.

@macteo
Copy link
Author

macteo commented Sep 1, 2016

I've got another crash, with different exception, but I think the cause is the same.

mapbox-crashlog-2.txt

@macteo
Copy link
Author

macteo commented Sep 1, 2016

I'm not interacting with the map or other MapBox APIs while the app is in background.
Do you think that removing the map from it's superview before entering background can solve the issue?
Or there still can be some other orphaned object (a singleton maybe) that will cause the issue?

The app dying while in background is a real blocking issue as the app itself won't be wake-up again to receive location updates until the user taps again on the icon.

@friedbunny
Copy link
Contributor

friedbunny commented Oct 13, 2016

For searchability, here’s the crashed thread from the original post:

Fatal Exception: mapbox::sqlite::Exception: authorization denied

#13. Crashed: DefaultFileSource
0  Tralio                         0x100106c54 CLSProcessRecordAllThreads + 1572
1  Tralio                         0x100106c54 CLSProcessRecordAllThreads + 1572
2  Tralio                         0x100106b10 CLSProcessRecordAllThreads + 1248
3  Tralio                         0x1000f6a5c CLSHandler + 48
4  Tralio                         0x100104b28 __CLSExceptionRecord_block_invoke + 92
5  libdispatch.dylib              0x184ae51c0 <redacted> + 16
6  libdispatch.dylib              0x184af2860 <redacted> + 84
7  Tralio                         0x1001045cc CLSExceptionRecord + 212
8  Tralio                         0x1001040fc CLSTerminateHandler() + 616
9  libc++abi.dylib                0x18468366c std::__terminate(void (*)()) + 16
10 libc++abi.dylib                0x184683234 __cxa_rethrow + 144
11 Mapbox                         0x1005a915c mbgl::OfflineDatabase::ensureSchema() + 844
12 Mapbox                         0x1005a8d8c mbgl::OfflineDatabase::OfflineDatabase(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, unsigned long long) + 92
13 Mapbox                         0x10059b304 void mbgl::util::Thread<mbgl::DefaultFileSource::Impl>::run<std::__1::tuple<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, unsigned long long&>, 0ul, 1ul>(std::__1::tuple<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, unsigned long long&>&&, std::__1::integer_sequence<unsigned long, 0ul, 1ul>) + 88
14 Mapbox                         0x10059b268 std::__1::__thread_proxy<std::__1::tuple<mbgl::util::Thread<mbgl::DefaultFileSource::Impl>::Thread<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, unsigned long long&>(mbgl::util::ThreadContext const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&&&, unsigned long long&&&)::'lambda'()> >(void*, void*) + 136
15 libsystem_pthread.dylib        0x184cef860 <redacted> + 240
16 libsystem_pthread.dylib        0x184cef770 _pthread_start + 282
17 libsystem_pthread.dylib        0x184cecdbc thread_start + 4

And from #6205 (comment):

Fatal Exception: mapbox::sqlite::Exception: disk I/O error

#10. Crashed: DefaultFileSource
0  Tralio                         0x100096ae4 CLSProcessRecordAllThreads + 1572
1  Tralio                         0x100096ae4 CLSProcessRecordAllThreads + 1572
2  Tralio                         0x1000969a0 CLSProcessRecordAllThreads + 1248
3  Tralio                         0x1000868ec CLSHandler + 48
4  Tralio                         0x1000949b8 __CLSExceptionRecord_block_invoke + 92
5  libdispatch.dylib              0x1804fd1c0 _dispatch_client_callout + 16
6  libdispatch.dylib              0x18050a860 _dispatch_barrier_sync_f_invoke + 84
7  Tralio                         0x10009445c CLSExceptionRecord + 212
8  Tralio                         0x100093f8c CLSTerminateHandler() + 616
9  libc++abi.dylib                0x18009b66c std::__terminate(void (*)()) + 16
10 libc++abi.dylib                0x18009b234 __cxa_rethrow + 144
11 libobjc.A.dylib                0x1800ac71c objc_exception_rethrow + 44
12 CoreFoundation                 0x18154e0bc CFRunLoopRunSpecific + 560
13 CoreFoundation                 0x18159b8d4 CFRunLoopRun + 112
14 Mapbox                         0x10054b348 void mbgl::util::Thread<mbgl::DefaultFileSource::Impl>::run<std::__1::tuple<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, unsigned long long&>, 0ul, 1ul>(std::__1::tuple<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, unsigned long long&>&&, std::__1::integer_sequence<unsigned long, 0ul, 1ul>) + 156
15 Mapbox                         0x10054b268 std::__1::__thread_proxy<std::__1::tuple<mbgl::util::Thread<mbgl::DefaultFileSource::Impl>::Thread<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, unsigned long long&>(mbgl::util::ThreadContext const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&&&, unsigned long long&&&)::'lambda'()> >(void*, void*) + 136
16 libsystem_pthread.dylib        0x180707860 _pthread_body + 240
17 libsystem_pthread.dylib        0x180707770 _pthread_body + 282
18 libsystem_pthread.dylib        0x180704dbc thread_start + 4

@boundsj
Copy link
Contributor

boundsj commented Mar 2, 2017

We expect that this issue will be resolved by #8125 that is in the Mapbox iOS SDK as of 3.5.0 beta 2. I'll leave this issue open for tracking until we can collect more evidence that the sqlite errors noted here no longer occur.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
crash iOS Mapbox Maps SDK for iOS offline
Projects
None yet
Development

No branches or pull requests

5 participants