Skip to content
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

Cannot access database on the main thread #487

Closed
BenazirSh opened this issue Oct 28, 2020 · 7 comments · Fixed by #592
Closed

Cannot access database on the main thread #487

BenazirSh opened this issue Oct 28, 2020 · 7 comments · Fixed by #592
Labels
bug Something isn't working incomplete This issue needs more data in order to be triaged

Comments

@BenazirSh
Copy link

Exception: java.lang.IllegalStateException
java.lang.IllegalStateException: Cannot access database on the main thread since it may potentially lock the UI for a long period of time.
at androidx.room.RoomDatabase.assertNotMainThread(RoomDatabase.java:267)
at androidx.room.RoomDatabase.beginTransaction(RoomDatabase.java:351)
at com.chuckerteam.chucker.internal.data.room.HttpTransactionDao_Impl.update(HttpTransactionDao_Impl.java:345)
at com.chuckerteam.chucker.internal.data.repository.HttpTransactionDatabaseRepository.updateTransaction(HttpTransactionDatabaseRepository.kt:37)
at com.chuckerteam.chucker.api.ChuckerCollector.onResponseReceived$com_github_ChuckerTeam_Chucker_library(ChuckerCollector.kt:71)
at com.chuckerteam.chucker.api.ChuckerInterceptor$ChuckerTransactionTeeCallback.onSuccess(ChuckerInterceptor.kt:242)
at com.chuckerteam.chucker.internal.support.TeeSource.close(TeeSource.kt:69)
at okio.RealBufferedSource.close(RealBufferedSource.kt:477)
at okio.ForwardingSource.close(ForwardingSource.kt:34)
at okio.RealBufferedSource.close(RealBufferedSource.kt:477)
at okio.RealBufferedSource$inputStream$1.close(RealBufferedSource.kt:170)
kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:56)
at android.os.Handler.handleCallback(Handler.java:914)
at android.os.Handler.dispatchMessage(Handler.java:100)
at android.os.Looper.loop(Looper.java:224)
at android.app.ActivityThread.main(ActivityThread.java:7560)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:539)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:950)

@BenazirSh BenazirSh changed the title Cannot access database on the main thread since it may potentially lock the UI for a long period of time. Cannot access database on the main thread Oct 28, 2020
@BenazirSh
Copy link
Author

I'm getting the error as above

@MiSikora
Copy link
Contributor

MiSikora commented Oct 28, 2020

Please update your issue with our bug report template. A sample code would also be helpful.

From your stack trace it looks like you are closing the response on the main thread (which might mean that it is also read on the main thread). You can fix it by processing/closing the response on a background thread and posting the result to the main thread.

As for the solution in the library it could be solved with a custom executor that processes results. I mentioned it in the next steps of #267. Although, to be perfectly honest, I'm not sure if we should change it just for this reason. Closing response on the main thread is not the best thing. It might require synchronisation and other work which can block the main thread even without ChuckerInterceptor. For example HTTP2 call – https://github.com/square/okhttp/blob/f1bc9d1d3339d0696e232a5d8a2d7830630a8242/okhttp/src/main/kotlin/okhttp3/internal/http2/Http2Stream.kt#L473-L487.

@MiSikora MiSikora added bug Something isn't working incomplete This issue needs more data in order to be triaged labels Oct 28, 2020
@adityat-sportsbet
Copy link

Screen Shot 2021-03-25 at 5 42 34 pm

I am getting the same error, on the latest version 3.4.0.
Works fine when chucker is disabled.

@MiSikora
Copy link
Contributor

MiSikora commented Mar 25, 2021

How does your Rx chain look like?

@ghost ghost added the Pending PR The resolution for the issue is in PR label Mar 27, 2021
@ghost ghost removed the Pending PR The resolution for the issue is in PR label Mar 29, 2021
@CompuGenius-Programs
Copy link

I had the same issue, spent a long time trying to get this and other packages working, finally figured out that I need to use the sonatype snapshot version.
Maybe add that to the readme, or add it to the main release?

@MiSikora
Copy link
Contributor

MiSikora commented Apr 18, 2022

Readme isn't a place to track issues and changes. There is the changelog for that type of stuff. We do mention snapshot versions in the readme, though.

@CompuGenius-Programs
Copy link

CompuGenius-Programs commented Apr 18, 2022 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working incomplete This issue needs more data in order to be triaged
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants