fix(ios): dispatch Dictionary access to main thread in offline controllers#1119
Open
mateusztylman wants to merge 1 commit intomapbox:mainfrom
Open
fix(ios): dispatch Dictionary access to main thread in offline controllers#1119mateusztylman wants to merge 1 commit intomapbox:mainfrom
mateusztylman wants to merge 1 commit intomapbox:mainfrom
Conversation
…llers Wrap progress and completion closures in DispatchQueue.main.async to prevent concurrent read/write access to handler dictionaries from MapboxCommon background threads, which caused EXC_BAD_ACCESS (SIGSEGV). Affected files: - TileStoreController.swift: tileRegionLoadProgressHandlers, tileRegionEstimateProgressHandlers - OfflineController.swift: progressHandlers Fixes mapbox#1116
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fix thread-unsafe
Dictionaryaccess inTileStoreController.swiftandOfflineController.swiftthat causesEXC_BAD_ACCESS (SIGSEGV)crashes when downloading tile regions or style packs.Fixes #1116
Problem
loadTileRegion,estimateTileRegion, andloadStylePackuse progress and completion closures that are called on MapboxCommon background threads. Both closures access shared handler dictionaries without synchronization:removeValue(forKey:)runs on a background thread (executeOnMainThreadonly wrapped thecompletioncall, not theremoveValuethat followed)Swift's
Dictionaryis not thread-safe for concurrent read+write. When multiple regions/packs have overlapping lifetimes, this causes crashes.Fix
Wrap both progress and completion closure bodies in
DispatchQueue.main.asyncso all dictionary access is serialized on the main thread. This also ensures Flutter event sink calls happen on the main thread, consistent with Flutter's platform channel contract.Files changed:
TileStoreController.swift-loadTileRegionandestimateTileRegionOfflineController.swift-loadStylePackCrash signatures (from production)