zed-industries/zed · error
Failed to initialize event loop handling of sleep/wake event
Error message
Failed to initialize event loop handling of sleep/wake events: {err:?} What it means
During X11Client::new, gpui spawns its event-loop machinery including a watcher that forwards system power (sleep/wake) events into the platform's common handler. If spawning/initializing that event-loop component fails, the whole client construction fails with this error wrapping the underlying error in Debug form.
Source
Thrown at crates/gpui_linux/src/linux/x11/client.rs:363
}
}
})
.map_err(|err| {
anyhow!("Failed to initialize event loop handling of foreground tasks: {err:?}")
})?;
handle
.insert_source(power_receiver, |event, _, client: &mut X11Client| {
if let calloop::channel::Event::Msg(event) = event {
client
.0
.borrow_mut()
.common
.handle_system_power_event(event);
}
})
.map_err(|err| {
anyhow!("Failed to initialize event loop handling of sleep/wake events: {err:?}")
})?;
let (xcb_connection, x_root_index) = XCBConnection::connect(None)?;
xcb_connection.prefetch_extension_information(xkb::X11_EXTENSION_NAME)?;
xcb_connection.prefetch_extension_information(randr::X11_EXTENSION_NAME)?;
xcb_connection.prefetch_extension_information(render::X11_EXTENSION_NAME)?;
xcb_connection.prefetch_extension_information(xinput::X11_EXTENSION_NAME)?;
// Announce to X server that XInput up to 2.4 is supported.
// Version 2.4 is needed for gesture events (GesturePinchBegin/Update/End).
// The server responds with the highest version it supports; if < 2.4,
// we must not request gesture event masks in XISelectEvents.
let xinput_version = get_reply(
|| "XInput XiQueryVersion failed",
xcb_connection.xinput_xi_query_version(2, 4),
)?;
assert!(
xinput_version.major_version >= 2,View on GitHub (pinned to 9d272b0363)
Solutions
- Read the wrapped `{err:?}` detail to identify the underlying initialization failure.
- Retry launching the app; transient spawn failures usually stem from temporary resource exhaustion.
- Check system limits (ulimit on threads/processes) and free memory if task spawning failed.
- Ensure you are running on a supported X11 session and that the display connection is healthy.
Defensive patterns
Strategy: try-catch
Try / catch
// The error Debug is embedded; surface the cause chain to the user
if let Err(e) = init_x11_platform() {
if e.to_string().contains("sleep/wake events") {
log::error!("X11 platform init failed at power-event setup: {e:#}");
// inspect system limits / resources before retrying
}
return Err(e);
} Prevention
- Run the app on a healthy, supported X11 session.
- Check thread/process ulimits on constrained systems before launching.
- Keep the executor alive until platform initialization completes.
- Log the wrapped {err:?} cause to pinpoint the failing subsystem.
When it happens
Trigger: Creating an X11 gpui platform when the background task or event-loop setup for sleep/wake (power) event handling returns an error — e.g. failure to spawn the watcher task on the executor or an inner initialization error propagated via map_err.
Common situations: Resource exhaustion (thread/task spawn failure) on constrained systems; executor shutdown during platform initialization; environment-specific failures where the power-event watcher cannot be set up while starting the app under X11.
Related errors
- `{}` must be a positive normal number or `randr`. Got `{}`
- `{}` must be a positive number or `randr`. Got `{}`
- X11 connection: File descriptor passing failed
- X11 connection: Insufficient memory
- Idle sleep prevention acquisition timed out after 10 seconds
AI-assisted analysis of zed-industries/zed@9d272b0363 (2026-09-12).
Data as JSON: /api/errors/4b7f7776053bc774.
Report an issue: GitHub.