javaeclipseswtchromium-embedded

Equo Chromium browser for Java/SWT crashes on Ubuntu


I have a Java/SWT program, and I am using the standard Browser widget that comes with the SWT library. Due to its shortcomings (more about that if you're interested), I am considering switching to Equo Chromium Community Edition, which seemed an alluring alternative (link here).

However, I can't even reproduce the sample code they have on github without having the JVM crashing.

In summary : I am running Ubuntu Gnome 22.04 with openJdk 17.0.1+12, SWT 4.3 and the crash happens outside the JVM in native code. The problematic frame is [libc.so.6+0x97ef4] pthread_mutex_lock+0x4

In details, here is my code, taken and simplified from the sample found on github (link here)

 package com.testmaven.test.equo;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import com.equo.chromium.ChromiumBrowser;
import com.equo.chromium.swt.Browser;

public class SampleSWT {
    private static final String URL = "https://docs.equo.dev/main/getting-started/introduction.html";

    public static void main(String[] args) throws ClassNotFoundException {

        ChromiumBrowser.earlyInit();
        Display display = Display.getDefault();
        
        Shell shell = new Shell(display);
        shell.setSize(300, 300);
        shell.setLayout(new GridLayout(1, false));
        shell.setText("Bug report");

            System.setProperty("chromium.debug", "true");
            ChromiumBrowser.earlyInit();
            
            Browser browser = new Browser(shell, SWT.NONE);
            browser.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
            browser.setUrl(URL);
            Button button = new Button(shell, SWT.PUSH);
            //button.setText("Hello");
            //button.pack();
            button.addSelectionListener(new SelectionAdapter() {
                @Override
                public void widgetSelected(SelectionEvent e) {
                    browser.execute(
                            "alert('hello')");
                    System.out.println("\nbutton clicked");
                }
            });

        
        shell.open();

        while (!shell.isDisposed()) {
            if (!display.readAndDispatch())
                display.sleep();
        }
    }
}

Here is the relevant part of my pom.xml file :

      <repositories>
    <repository>
        <id>Equo-Chromium</id>
        <url>https://dl.equo.dev/chromium-swt-ce/oss/mvn</url>
    </repository>
</repositories>

<dependency>
    <groupId>org.eclipse.swt</groupId>
    <artifactId>org.eclipse.swt.gtk.linux.x86_64</artifactId>
    <version>4.3</version>
    <scope>provided</scope>
</dependency>
<dependency>
    <groupId>commons-io</groupId>
    <artifactId>commons-io</artifactId>
    <version>2.17.0</version>
</dependency>
<dependency>
    <groupId>com.equo</groupId>
    <artifactId>com.equo.chromium</artifactId>
    <version>124.0.0</version>
</dependency>
<dependency>
    <groupId>com.equo</groupId>
    <artifactId>com.equo.chromium.cef.gtk.linux.x86_64</artifactId>
    <version>124.0.0</version>
</dependency>

  </dependencies>
  

Expected behaviour :

Actual behaviour :

#
# A fatal error has been detected by the Java Runtime Environment:
#
#  SIGSEGV (0xb) at pc=0x00007fef42a97ef4, pid=57972, tid=57977
#
# JRE version: OpenJDK Runtime Environment Temurin-17.0.1+12 (17.0.1+12) (build 17.0.1+12)
# Java VM: OpenJDK 64-Bit Server VM Temurin-17.0.1+12 (17.0.1+12, mixed mode, tiered, > compressed oops, compressed class ptrs, g1 gc, linux-amd64)
# Problematic frame:
# C  [libc.so.6+0x97ef4]  pthread_mutex_lock+0x4
#
# Core dump will be written. Default location: Core dumps may be processed with "/usr/share/apport/apport -p%p -s%s -c%c -d%d -P%P -u%u -g%g -- %E" (or dumping to /media/guillaume/Docs_cabine/Source/TestMaven/test.equo/core.57972)
#
# If you would like to submit a bug report, please visit:
#   https://github.com/adoptium/adoptium-support/issues
# The crash happened outside the Java Virtual Machine in native code.
# See problematic frame for where to report the bug.
#

---------------  S U M M A R Y ------------

Command Line: -Dfile.encoding=UTF-8 -XX:+ShowCodeDetailsInExceptionMessages > com.testmaven.test.equo.SampleSWT

Host: Intel(R) Core(TM) i7-8550U CPU @ 1.80GHz, 8 cores, 7G, Ubuntu 22.04.5 LTS
Time: Wed Oct  2 16:04:17 2024 CEST elapsed time: 6.717892 seconds (0d 0h 0m 6s)

---------------  T H R E A D  ---------------

Current thread (0x00007fef3c0248b0):  JavaThread "main" [_thread_in_native, id=57977, > stack(0x00007fef42900000,0x00007fef42a00000)]

Stack: [0x00007fef42900000,0x00007fef42a00000],  sp=0x00007fef429fa3b8,  free space=1000k
Native frames: (J=compiled Java code, j=interpreted, Vv=VM code, C=native code)
C  [libc.so.6+0x97ef4]  pthread_mutex_lock+0x4

Java frames: (J=compiled Java code, j=interpreted, Vv=VM code)
J 822  org.eclipse.swt.internal.gtk.GTK._gtk_main_do_event(J)V (0 bytes) @ > 0x00007fef31306ce1 [0x00007fef31306ca0+0x0000000000000041]
J 814 c1 org.eclipse.swt.widgets.Display.eventProc(JJ)J (185 bytes) @ 0x00007fef29ef8584 > [0x00007fef29ef80c0+0x00000000000004c4]
v  ~StubRoutines::call_stub
j  org.eclipse.swt.internal.gtk.GTK._gtk_dialog_run(J)I+0
j  org.eclipse.swt.internal.gtk.GTK.gtk_dialog_run(J)I+8
j  org.eclipse.swt.widgets.MessageBox.open()I+312
j  com.equo.chromium.swt.internal.Chromium.lambda$24(Lorg/cef/handler/CefJSDialogHandler$JSDialogType;ZLjava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/util/function/Consumer;)V+183
j  com.equo.chromium.swt.internal.Chromium$$Lambda$49+0x0000000100124f50.run()V+28
j  org.eclipse.swt.widgets.RunnableLock.run(Lorg/eclipse/swt/widgets/Display;)V+11
J 745 c1 org.eclipse.swt.widgets.Synchronizer.runAsyncMessages(Z)Z (192 bytes) @ 0x00007fef29ee00f4 [0x00007fef29edff60+0x0000000000000194]
J 720 c1 org.eclipse.swt.widgets.Display.readAndDispatch()Z (79 bytes) @ 0x00007fef29ed40d4 [0x00007fef29ed3ce0+0x00000000000003f4]
j  com.testmaven.test.equo.SampleSWT.main([Ljava/lang/String;)V+121
v  ~StubRoutines::call_stub

siginfo: si_signo: 11 (SIGSEGV), si_code: 1 (SEGV_MAPERR), si_addr: 0x0000000000000010

Register to memory mapping:

What I have tried :

  1. Commenting out the following two lines will prevent the UI from crashing on startup
//button.setText("hello")
//button.pack();

In this case, the browser widget will load the URL as expected. Clicking on the button, however, will make the UI crash, with the same output in the console. Note however that and I can hear the "plop" noise associated with the javascript 'alert()' function right before it crashes, and System.println("button clicked") does work, as in the following output :

button clicked
#
# A fatal error has been detected by the Java Runtime Environment:
#
#  SIGSEGV (0xb) at pc=0x00007fef42a97ef4, pid=57972, tid=57977
  1. When running multiple tests, the behavior is not always consistent. Logging out of my Gnome session and logging in again will make the system behave again like I describe above.

  2. I have tried other versions of Ubuntu, and tested that same code with Wayland instead of Xorg, even tried Unity instead of Gnome, with the same results.

  3. Googling "problematic frame [libc.so.6+0x97ef4] pthread_mutex_lock+0x4" does return several results, but in each case, either they didn't find a convincing solution, or it is above my level of knowledge and understanding.

Questions

Does anyone have any experience using Equo Chromium with SWT on Ubuntu ? From what I can gather, the crash does seem to be related to certain things happening in the UI, which make me think of a threading issue. Do you think this should be considered as a bug in equo.chromium.cef.gtk.linux.x86_64 ?


Solution

  • I'm one of the developers of Equo Chromium. It looks like your application is missing the -Dchromium.init_threads=true property, which is necessary on certain Linux systems due to a bug in Xlib+GTK. Our sample applications do include this property.

    Additionally, just FYI, calling ChromiumBrowser.earlyInit() will only have an effect if called before the first browser in the application is created. Once a browser is initialized, calling it again won't have any impact.