Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ensure ReentrantLock is unlocked after being locked, and on same thread #2759

Merged
merged 3 commits into from
Aug 26, 2024

Conversation

westnordost
Copy link
Collaborator

@westnordost westnordost commented Aug 23, 2024

fixes #2432

The reentrant locks were engaged unconditionally on the then-main thread but the async task was only started conditionally. The unlocking of the locks was managed by the async task.
This lead to two issues:

  • if the condition checked for in initializeFileDirsPaths was already met, the locks were engaged but never unlocked. Any subsequent attempt to lock would just block execution forever.

  • (hypothetical, not tested:) the thread id of the app's main thread when the async task finished and thus calls onPostExecute or onCancel on that thread may differ from the thread id of the app's main thread when initializeFileDirsPaths was invoked: E.g. if the app was sent to background and effectively re-started later by the Android system. However, reentrant locks require to be locked/unlocked on the same thread, otherwise they will throw an IllegalMonitorStateException. The previous mechanism could not ensure this.

In any case, I am pretty sure either of these two issues is the cause for #2432.

Copy link
Collaborator

@louwers louwers left a comment

Choose a reason for hiding this comment

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

Looks good! Thanks for digging into this.

We'll have a release out with this soon.

@louwers louwers enabled auto-merge (squash) August 26, 2024 10:03
@louwers louwers merged commit 30f3e41 into maplibre:main Aug 26, 2024
23 checks passed
TimSylvester added a commit to WetDogWeather/maplibre-gl-native that referenced this pull request Oct 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Crash on Android while in background
2 participants