-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Prevents the app from crashing when the foreground service fails to start #19987
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
Oops, something went wrong.
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.
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.
I won't be able to test this today, but wanted to ask if you were able to consistently reproduce the issue and test this workaround since I am not 100% sure what happens now when we start the services from the background.
Something else I noticed is that we never explicitly call
startForegoundService
for starting services that are promoted to the foreground, but I believe that's required (we simply callstartService
everywhere). Not sure if that could also be related to the crashes we see.Anyway, my point is that I don't know if the app will simply crash at some other point if the service starts but fail to call
startForeground
. Maybe we might also need to stop the service on thecatch
clause here.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.
Thank you for your feedback @thomashorta 🙇
I was able to reproduce the crash a couple of times and verified that it was user facing (crash popup). I wasn’t able to find specific consistent steps though (maybe due to the many exemptions) :(
Most related crash stack traces seem to go through the specific line.
I’ll have a 2nd look at this and iterate back if I manage to reproduce consistently.
True. I think in all cases we use
Context#startService(Intent)
. I'm not sure if explicitly callingstartForegoundService
would make a difference tbh.That's indeed a valid concern. My reasoning behind this (temporary) workaround was to catch just the exception thrown from the
startForeground
assuming that running background service could continue.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.
Yeah, that's indeed the case, so I think that will get rid of the crash we see. My concern is that another crash might pop up anyway at other service-related place.
I agree! I'm not entirely sure what
startForegroundService
does TBH, I think it might just set some flag in the system saying that we will callstartForeground
soon and if we don't it throws an Exception, but maybe just usingstartService
works as well 🤷🏼♂️I don't think the service will be able to run properly in the background since background services are very limited in regards to execution time. I guess that some other crash might pop up, but to be honest, I think this fix is a start towards a solution, and if another crash pops up we will have more details about what could be going on exactly.
That said, I will go ahead and approve this PR!