-
-
Notifications
You must be signed in to change notification settings - Fork 721
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
NPE while using by inject, due to lazy initialization in JobIntentService(koin v2.1.5) #797
Comments
Seeing something similar with 2.1.5, though I'm not entirely sure if it's Koin or something else. We are doing a fairly straightforward Crashes seem to be random, especially for a class that is constantly in use (used in every Retrofit/API call we make). If it were something more deep rooted, I would think we would see thousands of crashes, but only a couple dozen here. Stack: kotlin.KotlinNullPointerException: null
at kotlin.UnsafeLazyImpl.getValue(Lazy.kt:81)
at com.basecamp.hey.api.AuthInterceptor.getSession
at com.basecamp.hey.api.AuthInterceptor.setRefreshInProgress
at com.basecamp.hey.api.AuthInterceptor.getSession(AuthInterceptor.kt:0)
at com.basecamp.hey.api.AuthInterceptor.getResponse(AuthInterceptor.kt:60)
at com.basecamp.hey.api.AuthInterceptor.intercept(AuthInterceptor.kt:32)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:100)
at okhttp3.internal.connection.RealCall.getResponseWithInterceptorChain$okhttp(RealCall.kt:197)
at okhttp3.internal.connection.RealCall$AsyncCall.run(RealCall.kt:502)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
at java.lang.Thread.run(Thread.java:919) Line 60 of private val session by inject<Session>() Any help is appreciated! |
do you have more stack? |
We're encountering a very similar problem, just after upgrading
The 2 stack traces that we have, are happening when injecting databases or repositories with Dao classes (constructor injected) -don't know if it's coincidence for this-. We're using Room, I paste 3 crashs stack traces below :
Thank you in advance for taking a look at this serious problem affecting big number of our users. |
@arnaudgiuliani That's about all we have. It's coming from a crash log and I can't find a way to locally reproduce it where I might be able to grab more logs. |
@arnaudgiuliani for the last trace : #797 (comment) We are creating a module for Room DB like :
Further in a ViewModel we inject it like :
It seems like further accessing the instance |
This crash is quite considerable on our crash stats. Due to lack of activity on this thread we will simply downgrade the version to see where it works. @lateplate can you tell us from what version did you upgrade to 2.1.5 ? We have tried downgrading from 2.1.6 -> 2.1.4, but still see the crash. |
@shaileshmota We kept pretty up to date, so I believe we were on 2.1.4 previously. But do note that our crashes are pretty sporadic and not super frequent. |
Hello @lateplate, you already had crashes with version 2.1.4 or everything was fine with that version ? |
Couldn’t say for sure, unfortunately. Our crash data is pretty limited so I can’t say when it may have started happening.
[email protected] wrote:
“Hello @lateplate, you already had crashes with version 2.1.4 or everything was fine with that version ?”
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or unsubscribe.
|
After update from 2.0.0 to 2.1.5 we see a lot of crashes in production. But, I've reviewed code and found a critical change that possibly leads to this issue |
@arnaudgiuliani Any updates? |
I need your stacktrace and code usage. Hard to say like that :/ |
@arnaudgiuliani The stacktrace the same as mentions above in the issue. We have made the research and found that one of the reason of this bug is making lazy(LazyThreadSafetyMode.NONE). Could you please explain the reason of this change? |
It's something I can look at. |
We have the same errors since we use Koin to init Room and our DAOs, It's now the first error in crashlytics.
And we get; Fatal Exception: java.lang.NullPointerException
Looking forward an update on this error, thanks :) |
I will push a rc-4 with my last fix, can anyone test it? |
Yes we can make an internal build and then deploy it to 5% of our base and check if it still happen. |
rc-4 is online! |
Please, consider adding extensions, say |
to people that have lazy evaluation problem, is it mostly located in Android Not sure, it's super impecting for now to have standard |
The trade-off I can propose is :
Android UI Thread is one of the rare place where we have only 1 thread. What do you think? |
It may be confusing to have the tool that works differently in different places. Actually, it'd be nice to have a manual control on the threading while injecting anyway. For my projects, I've made two extension methods for this purpose, so I'm always sure about the threading:
P.S. In my projects, the vast majority of injections is made without synchronization, as I'm sure what threads access the injected resources. It may not be true for everybody though. |
If we check Android sources, they don't use Lazy - https://cs.android.com/androidx/platform/frameworks/support/+/androidx-master-dev:lifecycle/lifecycle-viewmodel-ktx/src/main/java/androidx/lifecycle/ViewModelProvider.kt;l=41?q=%20ViewModelLazy it's just a cached response. As in UI thread, we don't need more. For now, pessimist approach help everyone to get the right data. As an improvement, UI API could have something inspired by |
closing this issue for now. Let's keep in touch for better Lazy implementation for UI. |
On our side, no more errors since the rc-4. Thanks again ! |
I am using joinAll inside a jobintentservice. Also, i m initializing global objects via inject. This was working fine on v2.0.1. When i upgraded it to v2.1.5, two crashes have been logged in crashlytics
Fatal Exception: kotlin.KotlinNullPointerException
at kotlin.UnsafeLazyImpl.getValue(UnsafeLazyImpl.java:81)
at com.android.david.onboarding.services.SuggestionsService.getSplashRepo(SuggestionsService.java:1)
at com.android.david.onboarding.services.SuggestionsService.access$getSplashRepo$p(SuggestionsService.java:16)
at com.android.david.onboarding.services.SuggestionsService$onHandleWork$1$2.invokeSuspend(SuggestionsService.java:41)
at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(BaseContinuationImpl.java:33)
at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.java:56)
at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.java:571)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.java:738)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.java:678)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.java:665)
The text was updated successfully, but these errors were encountered: