-
Notifications
You must be signed in to change notification settings - Fork 868
Missing notifications due to stuck background workers #6837
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| Fixes uncaught exceptions in the SyncWorker to cause the worker to become stuck in the failure state |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -55,14 +55,16 @@ internal abstract class SessionSafeCoroutineWorker<PARAM : SessionWorkerParams>( | |
|
|
||
| // Make sure to inject before handling error as you may need some dependencies to process them. | ||
| injectWith(sessionComponent) | ||
| if (params.lastFailureMessage != null) { | ||
| // Forward error to the next workers | ||
| doOnError(params) | ||
| } else { | ||
| doSafeWork(params) | ||
|
|
||
| when (val lastFailureMessage = params.lastFailureMessage) { | ||
| null -> doSafeWork(params) | ||
| else -> { | ||
| // Forward error to the next workers | ||
| doOnError(params, lastFailureMessage) | ||
| } | ||
| } | ||
| } catch (throwable: Throwable) { | ||
| buildErrorResult(params, throwable.localizedMessage ?: "error") | ||
| buildErrorResult(params, "${throwable::class.java.name}: ${throwable.localizedMessage ?: "N/A error message"}") | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. added extra details about the error to help debug in the future |
||
| } | ||
| } | ||
|
|
||
|
|
@@ -89,10 +91,10 @@ internal abstract class SessionSafeCoroutineWorker<PARAM : SessionWorkerParams>( | |
| * This is called when the input parameters are correct, but contain an error from the previous worker. | ||
| */ | ||
| @CallSuper | ||
| open fun doOnError(params: PARAM): Result { | ||
| open fun doOnError(params: PARAM, failureMessage: String): Result { | ||
| // Forward the error | ||
| return Result.success(inputData) | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. previously we were always using the the fix is to consume the message and use the updated state for the result (so that it can be persisted without the
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OK, so we do not forward the error anymore to the next worker, since it has been removed from the It's still strange to me that the
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was also surprised by this, I think it's caused by the // requireBackgroundSync
val data = WorkerParamsFactory.toData(
Params(
sessionId = sessionId,
timeout = serverTimeoutInSeconds,
delay = 0L,
periodic = false,
random = UUID.randomUUID().toString() // create a unique id for each work request
)
)Logging the work request notice that as soon as the
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. after a bit more investigation, the default behaviour is -
another solution is to set an class Merger : InputMerger() {
override fun merge(inputs: MutableList<Data>): Data {
return inputs.first()
}
}I'm not aware of the historical details around the other workers but as they're based on
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
This should be far less confusing IMHO. The API of the work manager is so strange...
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes if there are chained workers we need to cancel using this mechanism, otherwise workers will be stuck if we return Failed state. This worker API is so bad...
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it will break some flow if we consume the failure, as we always return Success, if there is a chain of workers, the next one will be running when it shouldn't...
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. in those cases, should we be using
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'll rework the PR to make use of the
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. updated 1fd1a4e |
||
| .also { Timber.e("Work cancelled due to input error from parent") } | ||
| .also { Timber.e("Work cancelled due to input error from parent: $failureMessage") } | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. includes the failure message in the error log |
||
| } | ||
|
|
||
| companion object { | ||
|
|
||
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.
this line is the fix, matches the multiple event worker by ignoring previous results when appending new workers