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

[core, iOS] Fix MGLOfflinePack invalidate crash #15582

Merged
merged 10 commits into from
Sep 18, 2019

Conversation

julianrex
Copy link
Contributor

@julianrex julianrex commented Sep 6, 2019

EDIT:

This PR fixes a crash in invalidate due to nil pointer access, and adds code to catch an unhandled exception that is yet to be fully investigated.

The issue of accessing MGLOfflineStorage and MGLOfflinePack from multiple threads is NOT covered by this PR, and will hopefully be addressed by a refactor.

Until that point, it remains our recommendation that MGLOfflineStorage not be called from a background thread.


Original post:

WIP branch investigating issues around #15536.

The cause of the crash looks like a null pointer access in setOfflineRegionObserver in -[MGLOfflinePack invalidate] - triggered by 2 calls to invalidate, most likely on different threads.

This PR fixes the null pointer access, but in the process of testing this, and testing the scenario in #15536 an exception fired (I was also seeing what looked like FileSource crashes when the test fails - possibly when exit is called by the test runner).

This PR does NOT address any issues with accessing MGLOfflinePack and MGLOfflineStorage.packs from multiple threads.

Re: the exceptions, @tmpsantos as discussed earlier:

At a13dd1b - the test test15536RemovePacksWhileReloading will trigger an exception that's caught in CFRunLoopRun() (RunLoop::run()).

The exception is std::runtime_error("Malformed offline region definition"); thrown in offline.cpp. The region is "", i.e. an empty string. I do not know why.

What's going on here?

The subsequent commit 2143e77 adds a catch to OfflineDatabase::getRegionDefinition, and the test should complete.

@julianrex julianrex added iOS Mapbox Maps SDK for iOS crash ⚠️ DO NOT MERGE Work in progress, proof of concept, or on hold Core The cross-platform C++ core, aka mbgl labels Sep 6, 2019
Copy link
Contributor

@tmpsantos tmpsantos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OfflineDatabase LGTM

platform/default/src/mbgl/storage/offline_database.cpp Outdated Show resolved Hide resolved
@julianrex julianrex marked this pull request as ready for review September 12, 2019 13:10
@julianrex julianrex requested review from a team and fabian-guerra and removed request for a team and 1ec5 September 12, 2019 13:10
@julianrex julianrex removed the ⚠️ DO NOT MERGE Work in progress, proof of concept, or on hold label Sep 12, 2019
@julianrex julianrex added this to the release-ristretto milestone Sep 12, 2019
@julianrex julianrex self-assigned this Sep 16, 2019
Copy link
Contributor

@fabian-guerra fabian-guerra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for fixing this. Overall tests LGTM. Just a question regarding thread safeness.

platform/ios/CHANGELOG.md Outdated Show resolved Hide resolved
@julianrex julianrex merged commit 2b08c1d into master Sep 18, 2019
@julianrex julianrex deleted the jrex/15536-offline-pack-crash branch September 18, 2019 22:13
@chloekraw chloekraw changed the title Fix MGLOfflinePack invalidate crash [core, iOS] Fix MGLOfflinePack invalidate crash Nov 6, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Core The cross-platform C++ core, aka mbgl crash iOS Mapbox Maps SDK for iOS
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants