chromiumembedded / java-cef

Java Chromium Embedded Framework (JCEF). A simple framework for embedding Chromium-based browsers in other applications using the Java programming language.
https://bitbucket.org/chromiumembedded/java-cef
Other
629 stars 138 forks source link

Crash on linux and macOS in multi-threaded applications #477

Closed Rigner closed 3 weeks ago

Rigner commented 1 month ago

Describe the bug Hey, I'm trying to integrate JCEF into an existing application, which is highly multithreaded. Due to its nature, we cannot change that. JCEF crashes with SIGSEGV when initializing, with the same reason as https://github.com/chromiumembedded/java-cef/issues/41.

Unfortunately, the fix that was made there for backing up the signals and restoring them later doesn't work since another thread could cause a SIGSEGV while initializing JCEF, causing java to crash.

Would you have another idea to fix it ? I tried to patch CEF to disable the chromium crash reporter etc, since we don't need it (and it wouldn't work anyway since we're restoring the java signals), but never got it to build properly on my M1 mac (smth to do with sandbox lib). I would rather ask someone who has more experience to implement a proper fix for this.

To Reproduce Steps to reproduce the behavior:

  1. Boot multiple threads with a lot of logic being ran (can just dereference null objects to emulate SIGSEGV NPEs in a loop)
  2. Initialize JCEF
  3. Watch one of these threads crash with a SIGSEGV

Expected behavior JCEF should initialize without any crash

Screenshots N/A

Versions (please complete the following information):

Additional context All explained above.

AglishP commented 1 month ago

I'm not sure, but. I'm try to implement cef as external application, launched by request from spring app. And I have similar issue with cef. It's cruch when I using openJDK 17 and 21. But work fine when using temurin jdk 21. Same for 122 and 126 version on mac 14.5

Rigner commented 1 month ago

Hey @magreenblatt , we would love to get your feedback on this. Unfortunately this is quite a major issue, blocking a product release.

magreenblatt commented 1 month ago

Unfortunately, the fix that was made there for backing up the signals and restoring them later doesn't work since another thread could cause a SIGSEGV while initializing JCEF, causing java to crash.

Can you load/initialize JCEF during application startup, before creating all of the threads?

Rigner commented 1 month ago

I have tried that, literally on the first line after main(), unfortunately I was still getting issues because of a native thread (I think it was a leftover of the parent process, the joys of fork()...). We also have other native threads because of a Java Agent... Completely disabling signals is our only way out, we tried many things and never got a 100% working solution

Rigner commented 3 weeks ago

To update the status on this, the CEF PR has been merged with my fixes. My JCEF PR is still opened and ready to be merged.

You can download a build with the fix at https://github.com/Rigner/jcefbuild/releases/tag/1.0.16

cc @AglishP

Rigner commented 3 weeks ago

The PR has been merged on the main bitbucket repo with the fixes. Closing this issue now since it has been tested and fixed.