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

Fix for WorkManager not Initialized Crash #2052

Merged
merged 2 commits into from
Apr 12, 2024
Merged

Conversation

nan-li
Copy link
Contributor

@nan-li nan-li commented Apr 12, 2024

Description

One Line Summary

This is a fix for the non-reproducible WorkManager is not Initialized Crash we did in v4 already, with one small change in a try-catch.

Details

Motivation

Based on the the fix we made for v4 at #1721

The change I added was an additional try-catch after this comment from an SDK user after we made the v4 fix. They ran into the "WorkManager is already initialized" exception.

At the time that PR was made, the fixes were speculative and we didn't completely understand this crash. By now, and seeing other reports from SDK authors at our submitted Google Issue Tracker, I believe it is a bug in the library.

Scope

  • Before using WorkManager, check for its existence. Else, in rare cases that caused crashing, initialize it ourselves.
  • Additionally, as another layer to handling this issue, when initializing WorkManager ourselves, surround it in a try-catch as it is may be the slightest bit possible for another thread to initialize it in the interim between checking and initializing.
  • Provides a method to check if WorkManager is initialized in this process.

⚠️ Concerns ⚠️

  • There was a known issue with Hilt dependency manager that we were not able to figure out in the v4 of the SDK

Testing

Unit testing

No unit testing

Manual testing

Limited ability to test manually due to unable to reproduce

  • Tested normal app flow in an emulator
  • Receiving notifications in background and swiped away state
  • Opening app, etc.

Affected code checklist

  • Notifications
    • Display
    • Open
    • Push Processing
    • Confirm Deliveries
  • Outcomes
  • Sessions
  • In-App Messaging
  • REST API requests
  • Public API changes

Checklist

Overview

  • I have filled out all REQUIRED sections above
  • PR does one thing
  • Any Public API changes are explained in the PR details and conform to existing APIs

Testing

  • I have included test coverage for these changes, or explained why they are not needed
  • All automated tests pass, or I explained why that is not possible
  • I have personally tested this on my device, or explained why that is not possible

Final pass

  • Code is as readable as possible.
  • I have reviewed this PR myself, ensuring it meets each checklist item

This change is Reviewable

* Before using WorkManager, check for its existence. Else, in rare cases that caused crashing, initialize it ourselves.
* Additionally, as another layer to handling this issue, when initializing WorkManager ourselves, surround it in a try-catch as it is may be the slightest bit possible for another thread to initialize it in the interim between checking and initializing.
* Provides a method to check if WorkManager is initialized in this process.
  - This is effectively the `WorkManager.isInitialized()` public method introduced in `androidx.work:work-*:2.8.0-alpha02`.
  - Please see https://android-review.googlesource.com/c/platform/frameworks/support/+/1941186 for the library's implementation
@nan-li nan-li requested a review from jkasten2 April 12, 2024 17:46
@nan-li nan-li merged commit 8898cb8 into main Apr 12, 2024
2 checks passed
@nan-li nan-li deleted the fix/v5_work_manager_crash branch April 12, 2024 21:44
@jkasten2 jkasten2 mentioned this pull request Apr 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants