Skip to content

Crash on Android When Closing PDF Page After Scrolling || java.lang.IllegalStateException: Already closed #976

@maneesh-techversant

Description

@maneesh-techversant

We are encountering an app crash on Android devices when a user is viewing a PDF using react-native-pdf and closes the page after scrolling through it. The issue is consistently reported in Firebase with an IllegalStateException: Already closed error in the stack trace.

Steps to Reproduce:

  1. Open a PDF with the react-native-pdf component.
  2. Scroll or slide through multiple pages.
  3. Close the PDF viewing page (e.g., by navigating away or closing the screen).
  4. The app crashes.

Stack Trace (Firebase Report):

E FATAL EXCEPTION: PDF renderer
Process: com.app, PID: [varies]
java.lang.IllegalStateException: Already closed
    at io.legere.pdfiumandroid.util.ConfigKt.handleAlreadyClosed(Config.kt:20)
    at io.legere.pdfiumandroid.PdfPage.close(PdfPage.kt:582)
    at kotlin.io.CloseableKt.closeFinally(Closeable.kt:56)
    at io.legere.pdfiumandroid.PdfiumCore.renderPageBitmap(PdfiumCore.kt:406)
    at com.github.barteksc.pdfviewer.PdfFile.renderPageBitmap(PdfFile.java:301)
    at com.github.barteksc.pdfviewer.RenderingHandler.proceed(RenderingHandler.java:109)
    at com.github.barteksc.pdfviewer.RenderingHandler.handleMessage(RenderingHandler.java:66)
    at android.os.Handler.dispatchMessage(Handler.java:117)
    at android.os.Looper.loopOnce(Looper.java:205)
    at android.os.Looper.loop(Looper.java:293)
    at android.os.HandlerThread.run(HandlerThread.java:110)

Environment:

  • Platform: Android
  • Library: react-native-pdf
  • react-native-pdf version: 7.0.0
  • React Native Version: 0.81.4
  • Affected on multiple Android device models

Expected Behavior:
Closing the PDF page should safely release resources without crashing the app.

Observed Behavior:
The app terminates with a fatal exception mentioning "Already closed" in the PDF renderer.

Additional Notes:

  • The issue is critical as it affects the core PDF viewing functionality and is being observed frequently in production.

Request:
Please investigate the page closure and resource disposal logic to ensure the PDF component handles repeated or premature closures gracefully. A fix or guidance to mitigate these crashes would be highly appreciated.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions