voelin-gpui: a window that cannot open ends the app with the reason, not a hang

When open_main_window failed (no usable Vulkan or GL driver), run() stored the
error and called cx.quit() inside the launch callback. GPUI's Linux platform
calls that callback before it starts its event loop, and calloop's
EventLoop::run clears its stop signal on entry, so the quit was lost: the
binary stayed alive with no window and no message (reproduced on a private
Xvfb with VK_DRIVER_FILES, __EGL_VENDOR_LIBRARY_DIRS and LIBGL_DRIVERS_PATH
pointing nowhere: exit 124 under `timeout`, nothing in the log after "Creating
colormap"), and the `failure` that main was to print was never returned. The
quit is a foreground task now, which runs inside the loop: the same run exits
with status 1 and "cannot open the main window / Failed to create surface".

With no display server at all GPUI starts its headless platform, whose
open_window succeeds with a window that draws nothing, so the same silent hang
came from there; open_main_window refuses a compositor named "headless" with
"no display: neither DISPLAY nor WAYLAND_DISPLAY names a display server".

tests/launch_failure.rs starts the built binary both ways (the driver case
under VOELIN_X11_TEST_DISPLAY, skipped where the machine's driver is found
anyway; the display case needs none) and fails when the process outlives two
minutes; with the old cx.quit() the driver test fails after 120 s, with the fix
both pass in a third of a second. docs/ui.md ("Running it") says what a missing
driver and a missing display look like; CHANGELOG.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
faumarayandClaude Sonnet 5.5 committed 2026-10-27 09:41:53 +03:00
1 parent 97d51fb226
commit a4694e944b
4 files changed
+196 -3

No files matched your search

+3 -1
View File
@@ -20,7 +20,9 @@ User-visible changes of the apps and the `tsgw` gateway. The format follows
every token, a few widgets and the icons (`VOELIN_DEV_THEME`,
`VOELIN_FONT_SCALE`, `VOELIN_WINDOW_SIZE`; screenshots with
`scripts/gpui-shot.sh`, docs/ui/). `VOELIN_METER=1` logs what it costs once a
second: the CPU by group of threads, the memory and its own counters. The Slint app (`voelin`) is unchanged and
second: the CPU by group of threads, the memory and its own counters. A
window that cannot open (no driver, no display server) ends the app with
the reason and exit status 1. The Slint app (`voelin`) is unchanged and
stays the app; both run on one engine until the GPUI one reaches parity
(docs/ui.md). It needs Vulkan or OpenGL at run time (Mesa's lavapipe renders
in software); no package ships it yet.
+14 -1
View File
@@ -77,6 +77,14 @@ fn open_main_window(
engine: HostedEngine,
counters: Counters,
) -> Result<()> {
// Without a display server GPUI falls back to a headless platform, which
// opens windows that draw nothing and runs until it is stopped.
if cx.compositor_name() == "headless" {
return Err(anyhow::anyhow!(
"no display: neither DISPLAY nor WAYLAND_DISPLAY names a display server"
))
.context("cannot open the main window");
}
let HostedEngine { engine, events, .. } = engine;
let app = cx.new({
let counters = counters.clone();
@@ -140,7 +148,12 @@ pub fn run() -> Result<()> {
);
if let Err(e) = open_main_window(cx, &switches, hosted, counters) {
*failure.borrow_mut() = Some(e);
cx.quit();
// Not `cx.quit()` here: GPUI's Linux platform runs this callback
// before it starts its event loop, and the loop forgets a stop
// asked for earlier (calloop clears its stop signal when it
// starts), so the process would stay with no window and no
// message. A task runs inside the loop.
cx.spawn(async move |cx| cx.update(|cx| cx.quit())).detach();
}
}
});
+154
View File
@@ -0,0 +1,154 @@
//! The binary's failure path, end to end: when the main window cannot be
//! opened (no display server, no Vulkan or GL driver), `voelin-gpui` prints
//! why and exits with status 1 instead of staying alive with no window and no
//! message.
//!
//! It has to start the real binary. GPUI's Linux platform runs the launch
//! callback before it starts its event loop, and the loop forgets a quit asked
//! for before it started, so a failure handled by quitting inside the
//! callback hung the process; the test platform of the unit tests has no such
//! loop and cannot show it.
//!
//! The no-driver test needs a test X server in `VOELIN_X11_TEST_DISPLAY` (an
//! Xvfb, as CI has; never the desktop's display) and is skipped without one.
#![cfg(target_os = "linux")]
use std::fs;
use std::os::unix::fs::PermissionsExt as _;
use std::path::{Path, PathBuf};
use std::process::{Command, ExitStatus, Stdio};
use std::time::{Duration, Instant};
/// Where the drivers are not: the Vulkan loader, EGL's vendor library
/// directory and Mesa's driver directory all point here.
const NOWHERE: &str = "/nonexistent-voelin-gpui-test";
/// Loaded machines are slow, so the wait is generous; a run that works takes a
/// second or two.
const WAIT: Duration = Duration::from_secs(120);
/// The scratch directory of one run, removed at the end.
struct Scratch(PathBuf);
impl Drop for Scratch {
fn drop(&mut self) {
let _ = fs::remove_dir_all(&self.0);
}
}
/// How a run of the binary went.
enum Outcome {
/// It ended, with this status and this much of the log.
Ended(ExitStatus, String),
/// It picked a GPU: the window can open, so nothing failed.
Opened,
/// It was still running after [`WAIT`] with no GPU picked.
Hung(String),
}
/// Run the binary with the drivers hidden (`hide_drivers`) on `display`
/// (none: no display server at all) and wait for it to end, to pick a GPU or
/// to run out of time. Nothing of the user's state, display or session bus is
/// in its environment.
fn run_binary(name: &str, display: Option<&str>, hide_drivers: bool) -> Outcome {
let scratch = Scratch(
Path::new(env!("CARGO_TARGET_TMPDIR")).join(format!("{name}-{}", std::process::id())),
);
let home = scratch.0.join("home");
let runtime = scratch.0.join("runtime");
fs::create_dir_all(&runtime).unwrap();
fs::set_permissions(&runtime, fs::Permissions::from_mode(0o700)).unwrap();
let log = scratch.0.join("stderr.log");
let mut command = Command::new(env!("CARGO_BIN_EXE_voelin-gpui"));
command
.env_remove("DISPLAY")
.env_remove("WAYLAND_DISPLAY")
.env_remove("WAYLAND_SOCKET")
.env_remove("XDG_SESSION_TYPE")
.env_remove("DBUS_SESSION_BUS_ADDRESS")
.env_remove("RUST_LOG")
.env("HOME", &home)
.env("XDG_RUNTIME_DIR", &runtime)
.env("XDG_CONFIG_HOME", home.join("config"))
.env("XDG_DATA_HOME", home.join("data"))
.env("XDG_STATE_HOME", home.join("state"))
.env("XDG_CACHE_HOME", home.join("cache"))
.env("VOELIN_DATA_DIR", home.join("voelin"))
// The log line that tells a GPU was picked.
.env("VOELIN_LOG", "warn,voelin_gpui=info,gpui_wgpu=info")
.stdin(Stdio::null())
.stdout(Stdio::null())
.stderr(fs::File::create(&log).unwrap());
if let Some(display) = display {
command.env("DISPLAY", display);
}
if hide_drivers {
command
.env("VK_DRIVER_FILES", format!("{NOWHERE}/vulkan.json"))
.env("VK_ICD_FILENAMES", format!("{NOWHERE}/vulkan.json"))
.env("__EGL_VENDOR_LIBRARY_DIRS", NOWHERE)
.env("__EGL_VENDOR_LIBRARY_FILENAMES", format!("{NOWHERE}/egl.json"))
.env("LIBGL_DRIVERS_PATH", NOWHERE);
}
let mut child = command.spawn().unwrap();
let deadline = Instant::now() + WAIT;
loop {
if let Some(status) = child.try_wait().unwrap() {
return Outcome::Ended(status, fs::read_to_string(&log).unwrap_or_default());
}
let seen = fs::read_to_string(&log).unwrap_or_default();
let outcome = if seen.contains("Selected GPU adapter") {
Outcome::Opened
} else if Instant::now() > deadline {
Outcome::Hung(seen)
} else {
std::thread::sleep(Duration::from_millis(50));
continue;
};
let _ = child.kill();
let _ = child.wait();
return outcome;
}
}
#[test]
fn a_window_that_cannot_open_for_want_of_a_driver_ends_the_binary_with_an_error() {
let Some(display) = std::env::var("VOELIN_X11_TEST_DISPLAY").ok().filter(|d| !d.is_empty())
else {
eprintln!("skipped: VOELIN_X11_TEST_DISPLAY is not set");
return;
};
match run_binary("no-driver", Some(&display), true) {
Outcome::Ended(status, seen) => {
assert_eq!(status.code(), Some(1), "{seen}");
assert!(seen.contains("cannot open the main window"), "{seen}");
}
Outcome::Opened => eprintln!(
"skipped: this machine's driver was found in spite of the environment, \
so the window can open"
),
Outcome::Hung(seen) => panic!(
"still running after {WAIT:?} with no window and no GPU: a quit asked for in the \
launch callback is lost\n{seen}"
),
}
}
#[test]
fn without_a_display_server_the_binary_ends_with_an_error() {
match run_binary("no-display", None, false) {
Outcome::Ended(status, seen) => {
assert_eq!(status.code(), Some(1), "{seen}");
assert!(seen.contains("cannot open the main window"), "{seen}");
assert!(seen.contains("no display"), "{seen}");
}
Outcome::Opened => panic!("a GPU was picked without a display server"),
Outcome::Hung(seen) => panic!(
"still running after {WAIT:?} with no window: GPUI's headless platform keeps \
the app alive\n{seen}"
),
}
}
+25 -1
View File
@@ -1005,7 +1005,8 @@ crates/voelin-gpui/
and a job from another thread reach the entity; the theme reaches
gpui-component, follows the window's appearance and the text size; the
Slint file's tokens equal the Rust ones (below); the icons and fonts load.
`cargo test -p voelin-gpui`.
`tests/launch_failure.rs` starts the built binary where its window cannot
open (below). `cargo test -p voelin-gpui`.
### Running it
@@ -1024,6 +1025,29 @@ run took is in the log ("Selected GPU adapter: ..."; the default filter shows
GPUI's adapter lines: `VOELIN_LOG` or `RUST_LOG` change it). On Wayland and
on X11 (a window manager is needed there for fullscreen and close requests).
A window that cannot open ends the app with the reason and exit status 1; it
does not stay up without a window. With no usable driver (none installed, or
`VK_DRIVER_FILES` pointing nowhere) the message is
```
Error: cannot open the main window
Caused by:
Failed to create surface: Failed to create surface for any enabled backend: {}
```
and above it the log has the Vulkan loader's own lines (`vkCreateInstance:
Found no drivers!`); install a driver or lavapipe. With no display server
(neither `DISPLAY` nor `WAYLAND_DISPLAY` set, over ssh for one) it is `cannot
open the main window`, caused by `no display: neither DISPLAY nor
WAYLAND_DISPLAY names a display server`; GPUI alone would start its headless
platform there, which opens windows that draw nothing and runs until it is
stopped. `tests/launch_failure.rs` starts the binary both ways (the driver one
needs the test display of `VOELIN_X11_TEST_DISPLAY`; it hides the drivers
through `VK_DRIVER_FILES`, `__EGL_VENDOR_LIBRARY_DIRS` and
`LIBGL_DRIVERS_PATH`, and is skipped where the machine's driver is found
anyway).
| Switch | Does |
|---|---|
| `VOELIN_OPEN=swatch` | the swatch page in place of the shell; the Slint front end's other pages are not here yet and are named in a warning |