java-cef icon indicating copy to clipboard operation
java-cef copied to clipboard

Crash on linux and macOS in multi-threaded applications

Open Rigner opened this issue 1 year ago • 4 comments

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):

  • OS: macOS 10.13 - 14.5, Ubuntu 22.10 (any macOS or linux)
  • Java Version: OpenJDK 8, 17 and 21
  • JCEF Version: ea25085 (https://github.com/Rigner/java-cef/tree/master which is basically the same as this one with just 1 extra commit)
  • CEF Version: 122.0.6261.112

Additional context All explained above.

Rigner avatar Jul 09 '24 14:07 Rigner

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

AglishP avatar Jul 16 '24 16:07 AglishP

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

Rigner avatar Jul 18 '24 19:07 Rigner

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?

magreenblatt avatar Jul 22 '24 19:07 magreenblatt

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 avatar Jul 22 '24 20:07 Rigner

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 avatar Aug 13 '24 15:08 Rigner

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

Rigner avatar Aug 14 '24 09:08 Rigner