-
Notifications
You must be signed in to change notification settings - Fork 308
Description
There is a source of deadlock in LegacyMapBoxImageGenerator.MergeImages between the method-level lock and the _backgroundImagesLocker.
A thread may acquire the lock on _backgroundImagesLocker in HandleMapNewTileAvaliable (sic) before calling UpdateImages -> GetImagesAsyncEnd -> MergeImages, where it blocks awaiting the method-level lock on this object.
A second thread can enter GetImagesAsyncEnd via other code paths that do not already have a lock on _backgroundImagesLocker, and acquire the method-level lock on this object, and then block trying to acquire the lock on _backgroundImagesLocker inside MergeImages.
The two threads then deadlock and all fetching of new tiles is blocked.
For a background layer, it would appear that the method-level lock on MergeImages is not required, and can be removed. The code then appears to run deadlock and error free. It has not been confirmed if this solution is error-free if the tile layer is either a normal layer or a variable layer.
The deadlock is demonstrated by a simple application that renders a TileAsyncLayer as a background layer. The map will stop working after a short period of panning and zooming to generate sufficient requests for tiles. Note that the tile layer must be a background layer to trigger the attempt to acquire the _backgroundImagesLocker in MergeImages. However, this is a common use-case for a tile layer.