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

[BUG] Caching causes crash #165

Open
MilanJovic92 opened this issue Oct 31, 2024 · 3 comments
Open

[BUG] Caching causes crash #165

MilanJovic92 opened this issue Oct 31, 2024 · 3 comments
Labels
bug Something isn't working

Comments

@MilanJovic92
Copy link

📝 Describe the Bug

The caching mechanism is crashing the application.

📖 Library Version

  • 2.1.1

🚶 Steps to Reproduce

I was unable to reproduce the problem localy.

🤔 Expected Behavior

I expect the app not to crash if there is a cache miss.

🖼️ Screenshots/Videos

/

📱 Smartphone Info:

Crashlytics has reported that it's mostly happening on Samsung devices.

💻 Code Snippets

This is how we use the PdfRenderView.

@Composable
fun PdfRendererComposable(
  file: File,
  statusCallBack: PdfRendererView.StatusCallBack,
  modifier: Modifier = Modifier,
) {
  AndroidView(
    factory = { context ->
      PdfRendererView(context).apply {
        statusListener = statusCallBack

        try {
          initWithFile(file)
        } catch (e: Exception) {
          statusCallBack.onError(e)
        }
      }
    },
    modifier = modifier,
  )
}

📜 Log Output/Stack Trace

Crash stack trace from the Firebase:

Fatal Exception: java.io.FileNotFoundException: /data/user/0/com.getyourguide.android/cache/___pdf___cache___/1: open failed: ENOENT (No such file or directory)
       at libcore.io.IoBridge.open(IoBridge.java:574)
       at java.io.FileOutputStream.<init>(FileOutputStream.java:236)
       at java.io.FileOutputStream.<init>(FileOutputStream.java:186)
       at com.rajat.pdfviewer.util.CacheManager$addBitmapToCache$1.invokeSuspend(CacheManager.kt:52)
       at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
       at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:101)
       at kotlinx.coroutines.internal.LimitedDispatcher$Worker.run(LimitedDispatcher.kt:113)
       at kotlinx.coroutines.scheduling.TaskImpl.run(Tasks.kt:89)
       at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt)
       at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:823)
       at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:720)
       at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt)
        

and

Caused by android.system.ErrnoException: open failed: ENOENT (No such file or directory)
       at libcore.io.Linux.open(Linux.java)
       at libcore.io.ForwardingOs.open(ForwardingOs.java:563)
       at libcore.io.BlockGuardOs.open(BlockGuardOs.java:274)
       at libcore.io.ForwardingOs.open(ForwardingOs.java:563)
       at android.app.ActivityThread$AndroidOs.open(ActivityThread.java:8756)
       at libcore.io.IoBridge.open(IoBridge.java:560)
       at java.io.FileOutputStream.<init>(FileOutputStream.java:236)
       at java.io.FileOutputStream.<init>(FileOutputStream.java:186)
       at com.rajat.pdfviewer.util.CacheManager$addBitmapToCache$1.invokeSuspend(CacheManager.kt:52)
       at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
       at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:101)
       at kotlinx.coroutines.internal.LimitedDispatcher$Worker.run(LimitedDispatcher.kt:113)
       at kotlinx.coroutines.scheduling.TaskImpl.run(Tasks.kt:89)
       at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt)
       at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:823)
       at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:720)
       at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt)
        

💬 Additional Context

Add any other context about the problem here. Mention if the issue is consistent, specific scenarios where the bug occurs, etc.


@MilanJovic92 MilanJovic92 added the bug Something isn't working label Oct 31, 2024
Copy link

Thank you for creating your first issue. We appreciate your help in making this project better. We will look into it, and get back to you soon. Need help or want to discuss this issue? Join our Discord community here to ask questions and discuss this issue live!

@mekutluca
Copy link

mekutluca commented Nov 9, 2024

Deleting the cached files helped me.

    val context = LocalContext.current

    PdfRendererViewCompose(
        url = pdfUrl,
        lifecycleOwner = LocalLifecycleOwner.current,
        statusCallBack = object : PdfRendererView.StatusCallBack {
            override fun onError(error: Throwable) {
                super.onError(error)

                context.cacheDir.listFiles { _, name ->
                    name.contains("pdf")
                }?.forEach { file ->
                    file.delete()
                }
            }
         ...

@MilanJovic92
Copy link
Author

Thank you for your suggestion @mekutluca, but the problem is we don't even get onError callback,
the code that is causing the crash is not handled in the library at all.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants