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: crash about persistent websocket being started from background [WPB-6551] #2745
fix: crash about persistent websocket being started from background [WPB-6551] #2745
Conversation
Test Results809 tests 809 ✅ 9m 10s ⏱️ Results for commit 98c23e3. ♻️ This comment has been updated with latest results. |
Build 3355 failed. |
APKs built during tests are available here. Scroll down to Artifacts! |
Build 3356 succeeded. The build produced the following APK's: |
…t-persistent-socket-service-crash
APKs built during tests are available here. Scroll down to Artifacts! |
Build 3364 succeeded. The build produced the following APK's: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🙇🏼♂️
APKs built during tests are available here. Scroll down to Artifacts! |
Build 3366 succeeded. The build produced the following APK's: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👌🏻
PR Submission Checklist for internal contributors
The PR Title
SQPIT-764
The PR Description
What's new in this PR?
Issues
Sometimes
startForeground
forPersistentWebSocketService
results inForegroundServiceStartNotAllowedException
.Causes (Optional)
This exception means that
startForeground
was executed when it's not allowed to, there are multiple restrictions on when foreground service can be started - more here: https://developer.android.com/develop/background-work/services/foreground-services#background-start-restriction-exemptionsFor us, we are allowed to start foreground service from Activity when the app is in the foreground and when the device is booted or app is updated (probably within 20 seconds) and we use
StartServiceReceiver
for that. The problem is probably that wecollect
in a coroutine, so it's just left hanging and receiving new values even in the background.Solutions
When
StartServiceReceiver
is called, get the list of persistent websocket statuses only once to make sure that we open the service within the permitted time frame. This persistent websocket flag can be changed only in settings by the user when the app is in the foreground so no need to observe for changes in this receiver - if changed then the service will be started fromWireActivityViewModel
.The logic of deciding whether the service should be started or not is extracted to dedicated use case and tested.
Testing
Test Coverage (Optional)
How to Test
There's no specific reproduction path, from the logs it looks like it could happen when the app was updated in the background and the sync was started so that the user's values in database are updated and
persistentWebSocketStatusListFlow
emits new list.PR Post Submission Checklist for internal contributors (Optional)
PR Post Merge Checklist for internal contributors
References
feat(conversation-list): Sort conversations by most emojis in the title #SQPIT-764
.