Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8351733

Crash when creating too many nested event loops

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: P3 P3
    • tbd
    • jfx23
    • javafx
    • None
    • Mac Studio running OS 15.3.1 (24D70)

      When creating a lot of nested event loops we can hit an OS limit that causes the app to crash. The problem occurs when a performSelectorOnMainThread block is executed by CFRunLoopRun which causes another performSelectorOnMainThread block to be executed by CFRunLoopRun and so on until we're about 250 levels deep. At that point the OS crashes the app with a specific message in the crash log:

      Application Specific Information:
      Too many nested CFRunLoopRuns

      At the JavaFX level this occurs when runLater block A schedules runLater block B and then enters a nested event loop, block B schedules runLater block C and then enters a nested event loop, and so on.

      The OS crash report isn't all that useful. It would be better if JavaFX threw a Java exception so the developer see a Java stack trace.

      To reproduce, run the attached test case MaxNestedLoops.java.

      The "No crash" button will spin up 200 event loops and then unwind them and print "Success!".

      The "Crash" button will attempt to spin up 254 event loops and the OS will crash the app.

      Edit 2025/03/27: the fix introduced a cross-platform limit of 200 nested event loops as a way to indicate the design issue in the application code.

            mfox Martin Fox
            mfox Martin Fox
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated: