Repository: electron/electron (language: cpp)

Issue:
[Bug]: SIGTRAP when starting electron >= 20.0.0-beta.9
### Preflight Checklist

- [X] I have read the [Contributing Guidelines](https://github.com/electron/electron/blob/main/CONTRIBUTING.md) for this project.
- [X] I agree to follow the [Code of Conduct](https://github.com/electron/electron/blob/main/CODE_OF_CONDUCT.md) that this project adheres to.
- [X] I have searched the [issue tracker](https://www.github.com/electron/electron/issues) for a bug report that matches the one I want to file, without success.

### Electron Version

20.0.0-beta.9 and 20.0.0-beta.10

### What operating system are you using?

Other Linux

### Operating System Version

Fedora 35

### What arch are you using?

x64

### Last Known Working Electron version

All older versions, including 19 and 20.0.0-beta.8

### Expected Behavior

Electron quickstart app should work, as should ANY other electron app, I have tested a bunch of them, but all gave the same results, after you install a recent 20 beta.

### Actual Behavior

They don't start if I use version 20.0.0-beta.9 or 20.0.0-beta.10, older versions *do* work. It only happens on *one* of the devices I own, *all* others are fine, but this one does not handle these new versions, while older ones work. This must have been introduced somewhere in [these commits between those releases](https://github.com/electron/electron/compare/v20.0.0-beta.8...v20.0.0-beta.9).

### Testcase Gist URL

https://github.com/electron/electron-quick-start/

### Additional Information

Running electron with `gdb` does not give a lot of info, unless I'm running it incorrectly, please see below and let me know if this should be done differently:
```gdb
jelmerro ~/electron-quick-start (master)$ gdb --args node node_modules/.bin/electron .
GNU gdb (GDB) Fedora 12.1-1.fc35
Copyright (C) 2022 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Type "show copying" and "show warranty" for details.
This GDB was configured as "x86_64-redhat-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<https://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
    <http://www.gnu.org/software/gdb/documentation/>.

For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from node...

This GDB supports auto-downloading debuginfo from the following URLs:
https://debuginfod.fedoraproject.org/ 
Enable debuginfod for this session? (y or [n]) y
Debuginfod has been enabled.
To make this setting permanent, add 'set debuginfod enabled on' to .gdbinit.
Reading symbols from /home/jelmerro/.cache/debuginfod_client/adca03b9b7e322bf173d4a6972adea6c254bf914/debuginfo...
(gdb) run
Starting program: /usr/bin/node node_modules/.bin/electron .
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib64/libthread_db.so.1".
[New Thread 0x7ffff23c0640 (LWP 12930)]
[New Thread 0x7ffff1bbf640 (LWP 12931)]
[New Thread 0x7ffff13be640 (LWP 12932)]
[New Thread 0x7ffff0bbd640 (LWP 12933)]
[New Thread 0x7fffebfff640 (LWP 12934)]
[New Thread 0x7ffff7fbe640 (LWP 12935)]
[Detaching after fork from child process 12936]
/home/jelmerro/electron-quick-start/node_modules/electron/dist/electron exited with signal SIGTRAP
[Thread 0x7fffebfff640 (LWP 12934) exited]
[Thread 0x7ffff0bbd640 (LWP 12933) exited]
[Thread 0x7ffff13be640 (LWP 12932) exited]
[Thread 0x7ffff1bbf640 (LWP 12931) exited]
[Thread 0x7ffff23c0640 (LWP 12930) exited]
[Thread 0x7ffff7fbe640 (LWP 12935) exited]
[Inferior 1 (process 12927) exited with code 01]

```


Discussion / hints:
Confirmed on Ubuntu 22.04. Reproducing is exactly as described by @Jelmerro: run quick-start, e.g. in fiddle, and `SIGTRAP` appears immediately. The regression appeared between -beta.8 and -beta.9.
https://github.com/electron/electron/compare/v20.0.0-beta.8...v20.0.0-beta.9

It's probably the 104.0.5112.39 bump at db0830e0f8d4aaffde0944aaee0983ec34f35c1a but I'll do some testing to confirm.
@ckerr @Jelmerro Sorry both, could I ask you what desktop environment you're both using? Here's the pattern I'm seeing on repro:

* Ubuntu 20.04, Wayland: Does not SIGTRAP
* Ubuntu 20.04, Xorg: Does not SIGTRAP
* Ubuntu 20.04, Unity: Does not SIGTRAP
* Ubuntu 22.04, Wayland: Does not SIGTRAP
* Ubuntu 22.04, Xorg: SIGTRAP
* Ubuntu 22.04, Unity: SIGTRAP

I wonder if this could be a Unity and/or Xorg bug? Or perhaps we're checking for the existence of something on Wayland that doesn't exist on Unity/Xorg?
Cinnamon here, so that would be Xorg, but other computers that run the same operating system and desktop environment *do* work with the new beta releases, as I run the same system on most devices.
I noticed something similar when trying to reproduce on Ubuntu 20.04 - I can’t repro at all on my Ubuntu 20.04 machine, regardless of environment. But @TGWKE could hit the SIGTRAP on Ubuntu 20.04, on every environment except Wayland. 🤔 
> I wonder if this could be a Unity and/or Xorg bug?

Does this need the https://github.com/electron/electron/labels/x11 label or could this be because of any other protocol?
> @ckerr @Jelmerro Sorry both, could I ask you what desktop environment you're both using?

Great question; I should've included that info in my previous comment. I'm seeing this in 22.04 with Xorg.

Fix patch:
diff --git a/shell/browser/electron_browser_main_parts.cc b/shell/browser/electron_browser_main_parts.cc
index 13bd28b53443c..b422d930769f8 100644
--- a/shell/browser/electron_browser_main_parts.cc
+++ b/shell/browser/electron_browser_main_parts.cc
@@ -278,12 +278,6 @@ void ElectronBrowserMainParts::PostEarlyInitialization() {
 }
 
 int ElectronBrowserMainParts::PreCreateThreads() {
-#if defined(USE_AURA)
-  if (!display::Screen::GetScreen()) {
-    screen_ = views::CreateDesktopScreen();
-  }
-#endif
-
   if (!views::LayoutProvider::Get())
     layout_provider_ = std::make_unique<views::LayoutProvider>();
 
@@ -314,6 +308,14 @@ int ElectronBrowserMainParts::PreCreateThreads() {
   // Load resources bundle according to locale.
   std::string loaded_locale = LoadResourceBundle(locale);
 
+#if defined(USE_AURA)
+  // NB: must be called _after_ locale resource bundle is loaded,
+  // because ui lib makes use of it in X11
+  if (!display::Screen::GetScreen()) {
+    screen_ = views::CreateDesktopScreen();
+  }
+#endif
+
   // Initialize the app locale.
   std::string app_locale = l10n_util::GetApplicationLocale(loaded_locale);
   ElectronBrowserClient::SetApplicationLocale(app_locale);


Test patch: