Repository: alacritty/alacritty (language: rust)

Issue:
Hangs on startup
OS: Linux
Version: alacritty 0.13.1
Wayland (ChromeOS 121.0.6167.131 beta)

Alacritty is hanging on startup. This started with version 0.13. It sometimes starts successfully, about 15% of the time, but otherwise it hangs in the same place every time:

<details>
<summary>WAYLAND_DEBUG=1 alacritty --print-events -vvv --config-file /dev/null</summary>

```
¶ WAYLAND_DEBUG=1 alacritty --print-events -vvv --config-file /dev/null
[4010321.829]  -> wl_display@1.get_registry(new id wl_registry@2)
[4010321.986]  -> wl_display@1.sync(new id wl_callback@3)
[4010422.972] wl_display@1.delete_id(3)
[4010424.223] wl_registry@2.global(1, "wl_compositor", 4)
[4010424.440] wl_registry@2.global(2, "wl_shm", 1)
[4010424.463] wl_registry@2.global(3, "wl_drm", 2)
[4010424.475] wl_registry@2.global(4, "wl_subcompositor", 1)
[4010424.485] wl_registry@2.global(5, "wl_output", 3)
[4010424.497] wl_registry@2.global(6, "wl_data_device_manager", 3)
[4010424.507] wl_registry@2.global(7, "wp_fractional_scale_manager_v1", 1)
[4010424.517] wl_registry@2.global(8, "wp_viewporter", 1)
[4010424.526] wl_registry@2.global(9, "zwp_tablet_manager_v2", 1)
[4010424.537] wl_registry@2.global(10, "wl_seat", 5)
[4010424.546] wl_registry@2.global(11, "gtk_shell1", 1)
[4010424.557] wl_registry@2.global(12, "wl_shell", 1)
[4010424.566] wl_registry@2.global(13, "zwp_pointer_constraints_v1", 1)
[4010424.575] wl_registry@2.global(14, "zwp_relative_pointer_manager_v1", 1)
[4010424.586] wl_registry@2.global(15, "zwp_idle_inhibit_manager_v1", 1)
[4010424.595] wl_registry@2.global(16, "zwp_text_input_manager_v1", 1)
[4010424.706] wl_registry@2.global(17, "zcr_text_input_crostini_manager_v1", 1)
[4010424.731] wl_registry@2.global(18, "zcr_text_input_x11_v1", 1)
[4010424.743] wl_registry@2.global(19, "zcr_text_input_extension_v1", 11)
[4010424.756] wl_registry@2.global(20, "xdg_wm_base", 3)
[4010424.766] wl_callback@3.done(19267)
[4010425.304]  -> wl_registry@2.bind(1, "wl_compositor", 4, new id [unknown]@3)
[4010425.677]  -> wl_registry@2.bind(4, "wl_subcompositor", 1, new id [unknown]@4)
[4010425.802]  -> wl_registry@2.bind(5, "wl_output", 3, new id [unknown]@5)
[4010425.935]  -> wl_registry@2.bind(10, "wl_seat", 5, new id [unknown]@6)
[4010425.992]  -> wl_registry@2.bind(7, "wp_fractional_scale_manager_v1", 1, new id [unknown]@7)
[4010426.017]  -> wl_registry@2.bind(8, "wp_viewporter", 1, new id [unknown]@8)
[4010426.102]  -> wl_registry@2.bind(2, "wl_shm", 1, new id [unknown]@9)
[4010426.124]  -> wl_registry@2.bind(20, "xdg_wm_base", 3, new id [unknown]@10)
[4010426.149]  -> wl_registry@2.bind(14, "zwp_relative_pointer_manager_v1", 1, new id [unknown]@11)
[4010426.166]  -> wl_registry@2.bind(13, "zwp_pointer_constraints_v1", 1, new id [unknown]@12)
[4010426.193]  -> wl_display@1.sync(new id wl_callback@13)
[4010433.157] wl_output@5.geometry(0, 0, 260, 146, 0, "unknown", "unknown", 0)
[4010433.274] wl_output@5.mode(3, 1366, 768, 60000)
[4010433.312] wl_output@5.scale(1)
[4010433.328] wl_output@5.done()
[4010433.339] wl_seat@6.name("default")
[4010433.475] wl_seat@6.capabilities(7)
[4010433.559]  -> wl_seat@6.get_keyboard(new id wl_keyboard@14)
[4010462.791]  -> wl_compositor@3.create_surface(new id wl_surface@15)
[4010462.912]  -> wl_seat@6.get_pointer(new id wl_pointer@16)
[4010470.037]  -> zwp_relative_pointer_manager_v1@11.get_relative_pointer(new id zwp_relative_pointer_v1@17, wl_pointer@16)
[4010470.195]  -> wl_seat@6.get_touch(new id wl_touch@18)
[4010471.610] wl_display@1.delete_id(13)
[4010471.786] wl_shm@9.format(842094158)
[4010471.812] wl_shm@9.format(875708993)
[4010471.822] wl_shm@9.format(875709016)
[4010471.831] wl_shm@9.format(0)
[4010471.839] wl_shm@9.format(1)
[4010471.846] wl_shm@9.format(909199186)
[4010471.854] wl_callback@13.done(19267)
Created log file at "/tmp/Alacritty-8413.log"
[0.000034000s] [INFO ] [alacritty] Welcome to Alacritty
[0.004455077s] [INFO ] [alacritty] Version 0.13.1
[0.004718847s] [INFO ] [alacritty] Running on Wayland
[0.008538847s] [INFO ] [alacritty] Configuration files loaded from:
                                     "/dev/null"
[0.032246231s] [INFO ] [alacritty] winit event: NewEvents(Init)
[0.032501385s] [INFO ] [alacritty] winit event: Resumed
[4010512.258]  -> wl_display@1.get_registry(new id wl_registry@13)
[4010512.399]  -> wl_display@1.sync(new id wl_callback@19)
[4010515.932] wl_registry@13.global(1, "wl_compositor", 4)
[4010516.057] wl_registry@13.global(2, "wl_shm", 1)
[4010516.495] wl_registry@13.global(3, "wl_drm", 2)
[4010516.564] wl_registry@13.global(4, "wl_subcompositor", 1)
[4010516.593] wl_registry@13.global(5, "wl_output", 3)
[4010516.678] wl_registry@13.global(6, "wl_data_device_manager", 3)
[4010516.717] wl_registry@13.global(7, "wp_fractional_scale_manager_v1", 1)
[4010516.746] wl_registry@13.global(8, "wp_viewporter", 1)
[4010516.771] wl_registry@13.global(9, "zwp_tablet_manager_v2", 1)
[4010516.860] wl_registry@13.global(10, "wl_seat", 5)
[4010516.901] wl_registry@13.global(11, "gtk_shell1", 1)
[4010516.947] wl_registry@13.global(12, "wl_shell", 1)
[4010516.974] wl_registry@13.global(13, "zwp_pointer_constraints_v1", 1)
[4010516.999] wl_registry@13.global(14, "zwp_relative_pointer_manager_v1", 1)
[4010517.026] wl_registry@13.global(15, "zwp_idle_inhibit_manager_v1", 1)
[4010517.052] wl_registry@13.global(16, "zwp_text_input_manager_v1", 1)
[4010517.077] wl_registry@13.global(17, "zcr_text_input_crostini_manager_v1", 1)
[4010517.103] wl_registry@13.global(18, "zcr_text_input_x11_v1", 1)
[4010517.129] wl_registry@13.global(19, "zcr_text_input_extension_v1", 11)
[4010517.154] wl_registry@13.global(20, "xdg_wm_base", 3)
[4010522.178] wl_display@1.delete_id(19)
[4010522.274] wl_callback@19.done(19267)
[4010522.467]  -> wl_registry@13.bind(6, "wl_data_device_manager", 3, new id [unknown]@19)
[4010522.541]  -> wl_registry@13.bind(10, "wl_seat", 5, new id [unknown]@20)
[4010524.239] wl_seat@20.name("default")
[4010524.368] wl_seat@20.capabilities(7)
[4010524.430]  -> wl_seat@20.get_keyboard(new id wl_keyboard@21)
[4010524.476]  -> wl_data_device_manager@19.get_data_device(new id wl_data_device@22, wl_seat@20)
[4010524.549]  -> wl_seat@20.get_pointer(new id wl_pointer@23)
[4010536.527] wl_keyboard@21.keymap(1, fd 17, 47395)
[4010536.655] wl_keyboard@21.repeat_info(20, 500)
[4010545.792]  -> wl_display@1.get_registry(new id wl_registry@24)
[4010545.898]  -> wl_display@1.sync(new id wl_callback@25)
[4010546.560] wl_registry@24.global(1, "wl_compositor", 4)
[4010546.675] wl_registry@24.global(2, "wl_shm", 1)
[4010546.691] wl_registry@24.global(3, "wl_drm", 2)
[4010546.703] wl_registry@24.global(4, "wl_subcompositor", 1)
[4010546.713] wl_registry@24.global(5, "wl_output", 3)
[4010546.721] wl_registry@24.global(6, "wl_data_device_manager", 3)
[4010546.731] wl_registry@24.global(7, "wp_fractional_scale_manager_v1", 1)
[4010546.740] wl_registry@24.global(8, "wp_viewporter", 1)
[4010546.750] wl_registry@24.global(9, "zwp_tablet_manager_v2", 1)
[4010546.759] wl_registry@24.global(10, "wl_seat", 5)
[4010546.767] wl_registry@24.global(11, "gtk_shell1", 1)
[4010546.776] wl_registry@24.global(12, "wl_shell", 1)
[4010546.785] wl_registry@24.global(13, "zwp_pointer_constraints_v1", 1)
[4010546.794] wl_registry@24.global(14, "zwp_relative_pointer_manager_v1", 1)
[4010546.803] wl_registry@24.global(15, "zwp_idle_inhibit_manager_v1", 1)
[4010546.831] wl_registry@24.global(16, "zwp_text_input_manager_v1", 1)
[4010546.862] wl_registry@24.global(17, "zcr_text_input_crostini_manager_v1", 1)
[4010546.876] wl_registry@24.global(18, "zcr_text_input_x11_v1", 1)
[4010546.887] wl_registry@24.global(19, "zcr_text_input_extension_v1", 11)
[4010546.897] wl_registry@24.global(20, "xdg_wm_base", 3)
[4010552.773] wl_display@1.delete_id(25)
[4010552.792] wl_callback@25.done(19267)
[4010552.974]  -> wl_display@1.sync(new id wl_callback@25)
[4010555.851] wl_display@1.delete_id(25)
[4010555.878] wl_callback@25.done(19267)
[4010556.026]  -> wl_registry@24.bind(3, "wl_drm", 2, new id [unknown]@25)
[4010556.072]  -> wl_display@1.sync(new id wl_callback@26)
[4010561.090] wl_drm@25.format(875708993)
[4010561.232] wl_drm@25.format(875709016)
[4010561.154] wl_display@1.delete_id(26)
[4010561.250] wl_drm@25.format(875713089)
[4010561.324] wl_drm@25.format(875713112)
[4010561.337] wl_drm@25.format(909199186)
[4010561.347] wl_drm@25.device("/dev/dri/renderD128")
[4010562.279] wl_drm@25.capabilities(1)
[4010563.953] wl_callback@26.done(19267)
[0.248281847s] [INFO ] [alacritty] Using EGL 1.4
[0.248596000s] [DEBUG] [alacritty] Picked GL Config:
                                     buffer_type: Some(Rgb { r_size: 8, g_size: 8, b_size: 8 })
                                     alpha_size: 8
                                     num_samples: 0
                                     hardware_accelerated: true
                                     supports_transparency: Some(true)
                                     config_api: Api(OPENGL | GLES1 | GLES2 | GLES3)
                                     srgb_capable: true
[4010722.450]  -> wl_compositor@3.create_surface(new id wl_surface@26)
[4010722.542]  -> xdg_wm_base@10.get_xdg_surface(new id xdg_surface@27, wl_surface@26)
[4010722.586]  -> xdg_surface@27.get_toplevel(new id xdg_toplevel@28)
[4010722.662]  -> wp_viewporter@8.get_viewport(new id wp_viewport@29, wl_surface@26)
[4010722.703]  -> wp_fractional_scale_manager_v1@7.get_fractional_scale(new id wp_fractional_scale_v1@30, wl_surface@26)
[4010722.729]  -> wl_surface@26.set_opaque_region(nil)
[4010722.749]  -> xdg_toplevel@28.set_app_id("Alacritty")
[4010722.762]  -> xdg_toplevel@28.set_title("Alacritty")
[4010722.777]  -> xdg_toplevel@28.set_min_size(2, 1)
[4010722.803]  -> xdg_toplevel@28.set_max_size(0, 0)
[4010722.840]  -> wl_surface@26.commit()
[4010722.883]  -> wl_display@1.sync(new id wl_callback@31)
[4010722.916] wl_keyboard@14.keymap(1, fd 16, 47395)
[4010722.936] wl_keyboard@14.repeat_info(20, 500)
[4010731.802] wl_surface@26.enter(wl_output@5)
[4010733.809] wp_fractional_scale_v1@30.preferred_scale(120)
[4010733.896] xdg_toplevel@28.configure(0, 0, array[0])
[4010733.917] xdg_surface@27.configure(19268)
[4010733.987]  -> xdg_surface@27.ack_configure(19268)
[4010738.591] wl_display@1.delete_id(31)
[0.275902154s] [ERROR] [sctk_adwaita] XDG Settings Portal did not return response in time: timeout: 100ms, key: color-scheme
[4010748.851]  -> wl_shm@9.create_pool(new id wl_shm_pool@32, fd 23, 1)
[4010749.007]  -> wl_compositor@3.create_surface(new id wl_surface@33)
[4010749.108]  -> wl_subcompositor@4.get_subsurface(new id wl_subsurface@34, wl_surface@33, wl_surface@26)
[4010749.139]  -> wl_subsurface@34.set_sync()
[4010749.182]  -> wl_compositor@3.create_surface(new id wl_surface@35)
[4010749.221]  -> wl_subcompositor@4.get_subsurface(new id wl_subsurface@36, wl_surface@35, wl_surface@26)
[4010749.265]  -> wl_subsurface@36.set_sync()
[4010749.281]  -> wl_compositor@3.create_surface(new id wl_surface@37)
[4010749.332]  -> wl_subcompositor@4.get_subsurface(new id wl_subsurface@38, wl_surface@37, wl_surface@26)
[4010749.362]  -> wl_subsurface@38.set_sync()
[4010749.381]  -> wl_compositor@3.create_surface(new id wl_surface@39)
[4010749.400]  -> wl_subcompositor@4.get_subsurface(new id wl_subsurface@40, wl_surface@39, wl_surface@26)
[4010749.435]  -> wl_subsurface@40.set_sync()
[4010749.456]  -> wl_compositor@3.create_surface(new id wl_surface@41)
[4010749.489]  -> wl_subcompositor@4.get_subsurface(new id wl_subsurface@42, wl_surface@41, wl_surface@26)
[4010749.513]  -> wl_subsurface@42.set_sync()
[0.389990231s] [TRACE] [crossfont] Number of fonts is 182
[0.390342770s] [TRACE] [crossfont] Got font path="/usr/share/fonts/truetype/noto/NotoSans-Bold.ttf", index=0
[0.390720154s] [DEBUG] [crossfont] Loaded Face Face { ft_face: Font Face: Bold, load_flags: TARGET_LIGHT, render_mode: "Normal", lcd_filter: 1 }
[4010886.693]  -> wl_surface@26.set_opaque_region(nil)
[4010886.783]  -> xdg_surface@27.set_window_geometry(0, -35, 800, 635)
[4010886.801]  -> wp_viewport@29.set_destination(800, 600)
[4010886.827] wl_callback@31.done(19268)
^C
```
</details>

The relevant lines:

```
[4010733.809] wp_fractional_scale_v1@30.preferred_scale(120)
[4010733.896] xdg_toplevel@28.configure(0, 0, array[0])
[4010733.917] xdg_surface@27.configure(19268)
[4010733.987]  -> xdg_surface@27.ack_configure(19268)
[4010738.591] wl_display@1.delete_id(31)
…
[4010886.827] wl_callback@31.done(19268)
```

If you're clever, you can spot the bug from here, especially when compared to a successful run.

```
[ 547457.855] wl_display@1.delete_id(31)
[ 547457.881] wp_fractional_scale_v1@30.preferred_scale(120)
[ 547458.012] xdg_toplevel@28.configure(0, 0, array[0])
[ 547458.051] xdg_surface@23.configure(22088)
[ 547458.067] wl_callback@31.done(22088)
[ 547458.123]  -> xdg_surface@23.ack_configure(22088)
```

In that 150ms gap, a different thread drove wayland-backend into a deadlock.

This starts with commit https://github.com/alacritty/alacritty/commit/80d4daccc307622f8e604af4f36ac89ecccf5db7, and can be further isolated to just the copypasta update. The copypasta update can be isolated to https://github.com/alacritty/copypasta/commit/6bc2ea66f108a21f0009b315438c286371cafbf0, a smithay-clipboard update. The relevant smithay-clipboard commit is https://github.com/Smithay/smithay-clipboard/commit/31392200dcecbeb17672ee735ff2fc92620fa379, which overhauls the entire event loop handling.

The previous version of smithay-clipboard was polling every 50ms; the current version dispatches the event queue properly. As such, events can be delivered to the main queue when the main thread is not the one performing the read, and we hit a deadlock in wayland-rs.

https://github.com/Smithay/wayland-rs/blob/2d5e7df99f896fadcd0165f4d958fcb6b43522cb/wayland-client/src/event_queue.rs#L464-L483

The `Err` result of `dispatch_inner_queue` is ignored as documented, but if it returns `Ok` with something greater than 0, that is ignored. This causes `blocking_dispatch` to assume that there were no pendings events and so it should block until there are some. That causes this loop to get stuck, as `done` is true but we're blocking on the read:

https://github.com/Smithay/wayland-rs/blob/2d5e7df99f896fadcd0165f4d958fcb6b43522cb/wayland-client/src/event_queue.rs#L430-L432

And indeed, if I adjust the scale factor on my system, it unblocks and finishes starting up.

It's unclear to me why `dispatching_impl` needs to read the queue in two different ways, or whether smithay-clipboard or alacritty are somehow violating the threading requirements of wayland-rs, but this patch fixes it for me. https://github.com/Smithay/wayland-rs/pull/695


Discussion / hints:
I am facing the same issue on [Hyprland](https://hyprland.org/). I'm running `alacritty 0.13.1 (fe2a3c56)`.
Hi,

On one of my systems with Alacritty (0.13.1 (fe2a3c56)) is also hanging on start (Wayland session). When I sign into Gnome with X11 Alacritty does not hang. 

So what I observed is if I launch another application first (e.g. Geany text editor) then Alacritty I can successfully get Alacritty to show a prompt.

**Steps:**
1. Sign into Gnome Wayland Session.
2. Launch Geany.
3. Launch Alacritty.

Actual Result:
Alacritty will show command prompt in ZSH shell.

If you repeat the above test, does Alacritty no longer freeze?
gnome issue is a bit different #7465.

Fix patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 5473813c104..7ac53941ea0 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -12,6 +12,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
 - CLI env variables clearing configuration file variables
 - Vi inline search/semantic selection expanding across newlines
 - C0 and C1 codes being emitted in associated text when using kitty keyboard
+- Occasional hang on startup with some Wayland compositors
 
 ### Changed
 
diff --git a/Cargo.lock b/Cargo.lock
index 588d17c07b8..dfa6af34ed0 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -1410,9 +1410,9 @@ dependencies = [
 
 [[package]]
 name = "quick-xml"
-version = "0.30.0"
+version = "0.31.0"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "eff6510e86862b57b210fd8cbe8ed3f0d7d600b9c2863cd4549a2e033c66e956"
+checksum = "1004a344b30a54e2ee58d66a71b32d2db2feb0a31f9a2d302bf0536f15de2a33"
 dependencies = [
  "memchr",
 ]
@@ -2009,13 +2009,13 @@ checksum = "7ab9b36309365056cd639da3134bf87fa8f3d86008abf99e612384a6eecd459f"
 
 [[package]]
 name = "wayland-backend"
-version = "0.3.2"
+version = "0.3.3"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "19152ddd73f45f024ed4534d9ca2594e0ef252c1847695255dae47f34df9fbe4"
+checksum = "9d50fa61ce90d76474c87f5fc002828d81b32677340112b4ef08079a9d459a40"
 dependencies = [
  "cc",
  "downcast-rs",
- "nix",
+ "rustix",
  "scoped-tls",
  "smallvec",
  "wayland-sys",
@@ -2023,12 +2023,12 @@ dependencies = [
 
 [[package]]
 name = "wayland-client"
-version = "0.31.1"
+version = "0.31.2"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "1ca7d52347346f5473bf2f56705f360e8440873052e575e55890c4fa57843ed3"
+checksum = "82fb96ee935c2cea6668ccb470fb7771f6215d1691746c2d896b447a00ad3f1f"
 dependencies = [
  "bitflags 2.4.1",
- "nix",
+ "rustix",
  "wayland-backend",
  "wayland-scanner",
 ]
@@ -2046,20 +2046,20 @@ dependencies = [
 
 [[package]]
 name = "wayland-cursor"
-version = "0.31.0"
+version = "0.31.1"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "a44aa20ae986659d6c77d64d808a046996a932aa763913864dc40c359ef7ad5b"
+checksum = "71ce5fa868dd13d11a0d04c5e2e65726d0897be8de247c0c5a65886e283231ba"
 dependencies = [
- "nix",
+ "rustix",
  "wayland-client",
  "xcursor",
 ]
 
 [[package]]
 name = "wayland-protocols"
-version = "0.31.0"
+version = "0.31.2"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "e253d7107ba913923dc253967f35e8561a3c65f914543e46843c88ddd729e21c"
+checksum = "8f81f365b8b4a97f422ac0e8737c438024b5951734506b0e1d775c73030561f4"
 dependencies = [
  "bitflags 2.4.1",
  "wayland-backend",
@@ -2095,9 +2095,9 @@ dependencies = [
 
 [[package]]
 name = "wayland-scanner"
-version = "0.31.0"
+version = "0.31.1"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "fb8e28403665c9f9513202b7e1ed71ec56fde5c107816843fb14057910b2c09c"
+checksum = "63b3a62929287001986fb58c789dce9b67604a397c15c611ad9f747300b6c283"
 dependencies = [
  "proc-macro2",
  "quick-xml",


Test patch: