-
-
Notifications
You must be signed in to change notification settings - Fork 696
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
No definition found for class:'androidx.work.WorkerParameters' #1623
Comments
in koin version 3.4.0 it still cannot create the worker but it does not fully crash the app like it does in 3.4.2. I get this error
|
Looks like it's something similar to this issue because as one of the comments states, if I do
everything seems to work fine again |
That issue was not fully fixed. I have the same issue - it occurs rarely, which leads me to believe there is a race there. |
I can confirm that the issue persists with Koin Work Manager 3.4.3 and Core 3.4.3 using |
Even with
it still happens so not limited to workerOf |
anyone can help reproduce? |
I am only able to reproduce it on the device I specified in my OP, but in my app I have multiple work managers and the one that runs every 15 min (the minimum time available to run a work manager task) is the one I see it the most on. It can take a couple of days of constant running for it to happen at which time the app will crash. Trying to launch the app again (which starts the work manager as a one time task initially) it will crash. let the device sit for a bit and I can run the app again If it matters any I inject via constructor of the workmanager
Where BaseWorker is a class that all my workers implement
|
the othe thing to test, is to not use constructor injection but |
does that mean I need use |
yes, to check the current context |
Hi @arnaudgiuliani, I have been unable to replicate this error in debug mode. It seems to manifest exclusively on production devices and occurs very rarely. Our app is being utilized by ~200 devices and the error occurs ~3 times daily. After reviewing our release history, it can be related to the changes involving RepositoriesModule.kt
WorkersModule.kt
MyApplication.kt class MyApplication : Application(), KoinComponent {
override fun onCreate() {
super.onCreate()
// Koin
startKoin {
androidContext(this@MyApplication)
workManagerFactory()
modules(appModule) // Injects RepositoriesModule and WorkersModule
}
// SyncWorker - Periodic (15 minutes)
syncWorkerPeriodic()
}
private fun syncWorkerPeriodic() {
val constraintsBuilder: Constraints.Builder = Constraints.Builder()
.setRequiredNetworkType(NetworkType.CONNECTED)
val periodicWorkRequest = PeriodicWorkRequestBuilder<SyncWorker>(15, TimeUnit.MINUTES)
.setConstraints(constraintsBuilder.build())
.build()
WorkManager.getInstance(applicationContext)
.enqueueUniquePeriodicWork("syncWorkerPeriodic", ExistingPeriodicWorkPolicy.KEEP, periodicWorkRequest)
}
} SyncWorker.kt class SyncWorker(
context: Context,
params: WorkerParameters,
private val syncRepository: SyncRepository
) : CoroutineWorker(context, params), KoinComponent {
@OptIn(SyncRepository.SyncDelicateMethod::class)
override suspend fun doWork(): Result {
val showFeedback = inputData.getBoolean("showFeedback", false)
syncRepository.execWorker(showFeedback)
return Result.success()
}
}
Sentry Log: https://dpen.sentry.io/share/issue/212a63cf0f4d4e9e9ccc7237156a274a/ |
Yesterday I released a new app version with the code mentioned above. No error has surfaced yet, but it might be a coincidence due to limited testing. I'll keep an eye on it and provide updates here. val workersModule = module {
workerOf(::SyncWorker) { named<SyncWorker>() }
} |
Issue occurs here as well, but not reproducible in debug since it occurs very rarely. This will only be noticeable when the install-base is high enough. Currently about 13 users of the 2900 seem to be affected (about 0,5%). We need to inject some custom dependencies in the worker, and don't want to add a Koin dependency in the Workers themselves because we want to keep the Workers DI-agnostic. That's why we're using the following format for initialisation in the Koin module, as an example: worker(named<BackgroundWorker>()) {
BackgroundWorker(
context = androidContext(),
params = get(),
repository = get(),
dispatcher = get(named(IO_DISPATCHER))
)
} I'm guessing @lucianocn's approach with the |
I let it run over the weekend with without using constructor injection and using Does that also mean I could remove all usages of |
The following code didn't resolve the problem 😵💫 val workersModule = module {
workerOf(::SyncWorker) { named<SyncWorker>() }
} |
We've released our app with the |
@Mardaneus86 Facing the same problem at the moment. For your use of |
class YourWorker(context: Context,params: WorkerParameters) : CoroutineWorker(context, params), KoinComponent {
private val repository: Repository by inject() // <--
override suspend fun doWork(): Result {
// ...
}
} |
This is being caused by parameter resolution not being threadsafe, and is fixed by this PR. It's more likely to happen when multiple workers are triggered at the same time, which is often the case on production devices when It doesn't happen when using |
do you think it's the case of parameter resolution for each worker? kindof race condition/thread safety problem. |
I do, WorkManager manages a thread pool on which it creates workers, when enough workers are created at the same time there's a small chance that some are created on different threads in this pool which may trigger this bug. |
closing this, let's reopen after 3.5.0 version update if needed 👍 PR #1643 is merging |
We are still seeing this issue with Koin 3.5.1. It only happens to a small percentage of users, but it still happens reliably. Our flow is as follows:
Both workers from step 3 and 4 produce NoBeanDefFoundEception crashes. Android 33 |
@smuldr can you reopen a new issue? |
Describe the bug
Using 3.4.2 of koin work manager I am getting this error sometimes when trying to start a work manager instance
The definition of work manager in my application class is just this
This happens on a TCL Google TV device, Model# 32S356
I also have another Google TV from Sony and does not seem to happen though so it might be device dependent?
Can provide more information if needed
To Reproduce
Steps to reproduce the behavior:
Create a worker
Try to start worker upon app startup
Expected behavior
Worker launches without error
Koin project used and used version (please complete the following information):
koin work manager 3.4.2
koin core 3.4.2
Additional moduleDefinition
Work manager version 2.8.1
The text was updated successfully, but these errors were encountered: