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

Crash in WebView when entering nested loop

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: P3 P3
    • tbd
    • jfx16, jfx17.0.1, jfx18
    • javafx
    • None
    • web

      A basic WebView can cause the application to crash in libjfxwebkit.dylib (on macOS, it might occur on other platforms too).
      I have no deterministic usecase, but the crash can rather easily be reproduced by scrolling down fast on the https://sap.com website, using this snippet:

      ```
          @Override
          public void start(Stage stage) throws Exception {
               WebView wb1 = new WebView();
               wb1.getEngine().load("https://sap.com/");
               Scene scene = new Scene(wb1);
               stage.setScene(scene);
               stage.show();
           }
      ```
      Shortly before the crash, there is an Exception in the JavaFX Application Thread:
      ```
      Exception in thread "JavaFX Application Thread" java.lang.IllegalStateException: Cannot enter nested loop during animation or layout processing
      ```

      The stacktrace that leads to this contains
      ```Exception in thread "JavaFX Application Thread" java.lang.IllegalStateException: Cannot enter nested loop during animation or layout processing
      at javafx.graphics@18-internal/com.sun.javafx.tk.quantum.QuantumToolkit.enterNestedEventLoop(QuantumToolkit.java:635)
      at javafx.web@18-internal/com.sun.webkit.network.HTTP2Loader.waitForRequestToComplete(HTTP2Loader.java:460)
      at javafx.web@18-internal/com.sun.webkit.network.HTTP2Loader.<init>(HTTP2Loader.java:423)
      at javafx.web@18-internal/com.sun.webkit.network.HTTP2Loader.create(HTTP2Loader.java:137)
      at javafx.web@18-internal/com.sun.webkit.network.NetworkContext.fwkLoad(NetworkContext.java:168)
      at javafx.web@18-internal/com.sun.webkit.WebPage.twkUpdateRendering(Native Method)
      at javafx.web@18-internal/com.sun.webkit.WebPage.updateRendering(WebPage.java:667)
      at javafx.web@18-internal/com.sun.webkit.WebPage.updateContent(WebPage.java:660)
      at javafx.web@18-internal/com.sun.javafx.sg.prism.web.NGWebView.update(NGWebView.java:73)
      at javafx.web@18-internal/javafx.scene.web.WebView.handleStagePulse(WebView.java:1048)
      at javafx.web@18-internal/javafx.scene.web.WebView.lambda$new$0(WebView.java:283)
      at javafx.graphics@18-internal/com.sun.javafx.tk.Toolkit.lambda$runPulse$2(Toolkit.java:421)
      at java.base/java.security.AccessController.doPrivileged(AccessController.java:399)
      at javafx.graphics@18-internal/com.sun.javafx.tk.Toolkit.runPulse(Toolkit.java:420)
      at javafx.graphics@18-internal/com.sun.javafx.tk.Toolkit.firePulse(Toolkit.java:447)
      at javafx.graphics@18-internal/com.sun.javafx.tk.quantum.QuantumToolkit.pulse(QuantumToolkit.java:576)
      at javafx.graphics@18-internal/com.sun.javafx.tk.quantum.QuantumToolkit.pulse(QuantumToolkit.java:556)
      at javafx.graphics@18-internal/com.sun.javafx.tk.quantum.QuantumToolkit.pulseFromQueue(QuantumToolkit.java:549)
      at javafx.graphics@18-internal/com.sun.javafx.tk.quantum.QuantumToolkit.lambda$runToolkit$11(QuantumToolkit.java:353)
      at javafx.graphics@18-internal/com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:96)
      ```

      The interesting part is that `HTTP2Loader.waitForRequestToComplete` is invoked via `Toolkit.runPulse`. In that case, it is likely that enterNestedEventLoop will fail (or better, return immediately).

      Adding some debug shows that in all other cases, the invocation of `HTTP2Loader.waitForRequestToComplete` happens via the WebKit timer, outside the Pulse event:
      ``` at javafx.web@18-internal/com.sun.webkit.network.HTTP2Loader.waitForRequestToComplete(HTTP2Loader.java:448)
      at javafx.web@18-internal/com.sun.webkit.network.HTTP2Loader.<init>(HTTP2Loader.java:423)
      at javafx.web@18-internal/com.sun.webkit.network.HTTP2Loader.create(HTTP2Loader.java:137)
      at javafx.web@18-internal/com.sun.webkit.network.NetworkContext.fwkLoad(NetworkContext.java:168)
      at javafx.web@18-internal/com.sun.webkit.Timer.twkFireTimerEvent(Native Method)
      at javafx.web@18-internal/com.sun.webkit.Timer.fireTimerEvent(Timer.java:84)
      at javafx.web@18-internal/com.sun.webkit.Timer.notifyTick(Timer.java:65)
      at javafx.web@18-internal/javafx.scene.web.WebEngine$PulseTimer.lambda$static$0(WebEngine.java:1205)
      at javafx.graphics@18-internal/com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:457)
      at java.base/java.security.AccessController.doPrivileged(AccessController.java:399)
      at javafx.graphics@18-internal/com.sun.javafx.application.PlatformImpl.lambda$runLater$11(PlatformImpl.java:456)
      at javafx.graphics@18-internal/com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:96)
      ```


      The relevant part of the hotspot error log:
      ```
      Current thread (0x00007fbb0a30b400): JavaThread "JavaFX Application Thread" [_thread_in_native, id=775, stack(0x00007ffee6993000,0x00007ffee7193000)]

      Stack: [0x00007ffee6993000,0x00007ffee7193000], sp=0x00007ffee718e730, free space=8173k
      Native frames: (J=compiled Java code, j=interpreted, Vv=VM code, C=native code)
      C [libjfxwebkit.dylib+0x12982f7] Java_com_sun_webkit_network_URLLoaderBase_twkDidReceiveResponse+0x37
      j com.sun.webkit.network.URLLoaderBase.twkDidReceiveResponse(ILjava/lang/String;Ljava/lang/String;JLjava/lang/String;Ljava/lang/String;J)V+0 javafx.web@18-internal
      j com.sun.webkit.network.HTTP2Loader.lambda$didReceiveResponse$15(Ljava/net/http/HttpResponse$ResponseInfo;)V+28 javafx.web@18-internal
      j com.sun.webkit.network.HTTP2Loader$$Lambda$466+0x000000080038e658.run()V+8 javafx.web@18-internal
      J 2768 c1 com.sun.webkit.network.HTTP2Loader$$Lambda$453+0x0000000800337558.run()V javafx.web@18-internal (12 bytes) @ 0x000000010f4a69bc [0x000000010f4a6940+0x000000000000007c]
      J 2773 c1 com.sun.javafx.application.PlatformImpl$$Lambda$112+0x000000080010d830.run()Ljava/lang/Object; javafx.graphics@18-internal (8 bytes) @ 0x000000010f4a8124 [0x000000010f4a80c0+0x0000000000000064]
      J 2771 c1 com.sun.javafx.application.PlatformImpl.lambda$runLater$11(Ljava/lang/Runnable;Ljava/security/AccessControlContext;)V javafx.graphics@18-internal (41 bytes) @ 0x000000010f4a758c [0x000000010f4a74a0+0x00000000000000ec]
      J 2770 c1 com.sun.javafx.application.PlatformImpl$$Lambda$111+0x000000080010c9d8.run()V javafx.graphics@18-internal (12 bytes) @ 0x000000010f4a712c [0x000000010f4a70c0+0x000000000000006c]
      J 3268 c1 com.sun.glass.ui.InvokeLaterDispatcher$Future.run()V javafx.graphics@18-internal (91 bytes) @ 0x000000010f5a6d14 [0x000000010f5a6c00+0x0000000000000114]
      v ~StubRoutines::call_stub
      V [libjvm.dylib+0x510a41] JavaCalls::call_helper(JavaValue*, methodHandle const&, JavaCallArguments*, JavaThread*)+0x2a1
      V [libjvm.dylib+0x56c176] jni_invoke_nonstatic(JNIEnv_*, JavaValue*, _jobject*, JNICallType, _jmethodID*, JNI_ArgumentPusher*, JavaThread*)+0x2d6
      V [libjvm.dylib+0x5705c1] jni_CallVoidMethod+0x1a1
      C [libglass.dylib+0xc181] -[GlassRunnable run]+0x61
      C [Foundation+0x9ab4d] __NSThreadPerformPerform+0xcc
      C [CoreFoundation+0x845e2] __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__+0x11
      C [CoreFoundation+0x84581] __CFRunLoopDoSource0+0x67
      C [CoreFoundation+0x8439b] __CFRunLoopDoSources0+0xd1
      C [CoreFoundation+0x830ca] __CFRunLoopRun+0x39f
      C [CoreFoundation+0x826ce] CFRunLoopRunSpecific+0x1ce
      C [HIToolbox+0x2faad] RunCurrentEventLoopInMode+0x124
      C [HIToolbox+0x2f7c5] ReceiveNextEventCommon+0x248
      C [HIToolbox+0x2f569] _BlockUntilNextEventMatchingListInModeWithFilter+0x40
      C [AppKit+0x41659] _DPSNextEvent+0x373
      C [AppKit+0x3fea0] -[NSApplication(NSEvent) _nextEventMatchingEventMask:untilDate:inMode:dequeue:]+0x548
      C [AppKit+0x31bae] -[NSApplication run]+0x292
      C [libglass.dylib+0xe164] -[GlassApplication runLoop:]+0x764
      C [Foundation+0x9ab4d] __NSThreadPerformPerform+0xcc
      C [CoreFoundation+0x845e2] __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__+0x11
      C [CoreFoundation+0x84581] __CFRunLoopDoSource0+0x67
      C [CoreFoundation+0x8439b] __CFRunLoopDoSources0+0xd1
      C [CoreFoundation+0x830ca] __CFRunLoopRun+0x39f
      C [CoreFoundation+0x826ce] CFRunLoopRunSpecific+0x1ce
      C [libjli.dylib+0x70b2] CreateExecutionEnvironment+0x182
      C [libjli.dylib+0x2c15] JLI_Launch+0x585
      C [java+0x3bf1] main+0x191
      C [libdyld.dylib+0x1acc9] start+0x1
      ```

            arapte Ambarish Rapte
            jvos Johan Vos
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: