Wayland: app exits silently when flush() returns WouldBlock during EventFlow::Poll (transient EAGAIN treated as fatal)
Summary
On the Wayland backend, a transient WouldBlock (EAGAIN) from EventQueue::flush() in the EventFlow::Poll branch silently terminates the whole app, with no panic and no error output besides one warning line. The equivalent code path in the EventFlow::Wait branch already handles this condition correctly.
First of all, thanks for makepad — it's been a pleasure to build on!
Symptoms
The app exits instantly (exit code 0) while the user is interacting with it. The only trace in the log is:
[W] .../platform/src/os/linux/wayland/wayland_app.rs:93:13 - Wayland flush failed: Io error: Resource temporarily unavailable (os error 11)No Rust panic, no backtrace, nothing else — the process just disappears.
Environment
- makepad
devbranch at rev457e75a7ef1a69589a8434d49788666ff8f1a56a("Area: don't panic on a staleArea::Rect(#1171)") - Linux, Wayland compositor: niri (wlroots-based), 4K output, window tiled to ~1912×2150
- Reproduced with both real GPU rendering and Mesa llvmpipe
- The X11 backend is unaffected (same interaction works fine there)
Steps to reproduce
- Run any makepad-widgets app that performs a burst of full-window repaints on a click (in our case: clicking the blank canvas area under an open startup overlay/popup — the click triggers a marquee redraw plus a burst of
Event::NextFrameevents; we measured ~4876 NextFrame events in a single second). - Each frame commits a new Wayland buffer. With a fast GPU the loop paints unpaced, producing thousands of commits per second.
- The compositor momentarily falls behind staging buffers, the kernel send buffer fills, and the non-blocking socket send (
SendFlags::DONTWAITin wayland-backend'sBufferedSocket) returnsWouldBlock. - The app exits immediately (see root cause).
It's timing-dependent: sometimes the burst drains fast enough and the app survives, sometimes it dies within ~200 ms of the click.
Root cause
In platform/src/os/linux/wayland/wayland_app.rs, the EventFlow::Poll branch of the event loop treats any flush() error as fatal:
fn event_loop_poll(&mut self) {
if let Err(err) = self.event_queue.flush() {
crate::warning!("Wayland flush failed: {}", err);
self.terminate_event_loop();
return;
}
...The EventFlow::Wait branch in the same file (~line 58) already knows that a WouldBlock is transient and safe to retry:
// A WouldBlock just means the socket buffer is full; the messages stay
// queued and the next loop iteration retries, so only a dead connection
// is fatal.
if let Err(err) = self.event_queue.flush() {
let transient = matches!(
&err,
wayland_client::backend::WaylandError::Io(io)
if io.kind() == std::io::ErrorKind::WouldBlock
);
if !transient {
crate::warning!("Wayland flush failed: {}", err);
self.terminate_event_loop();
return;
}
}This is indeed safe to retry: wayland-backend's BufferedSocket::flush() only drains the bytes it managed to write and keeps the remainder queued, so a later flush attempt completes the send. The Poll branch is simply missing the same guard, so a momentary send-buffer congestion during a paint burst is treated as a dead connection and the event loop is torn down.
Proposed fix
Apply the same transient check in event_loop_poll() and skip the rest of the poll cycle so the retained backlog can drain:
fn event_loop_poll(&mut self) {
if let Err(err) = self.event_queue.flush() {
let transient = matches!(
&err,
wayland_client::backend::WaylandError::Io(io)
if io.kind() == std::io::ErrorKind::WouldBlock
);
if !transient {
crate::warning!("Wayland flush failed: {}", err);
self.terminate_event_loop();
return;
}
// Skip the rest of this poll cycle so the retained backlog can
// drain; the next loop iteration retries the flush.
return;
}
...We're carrying this as a local patch for now and it completely eliminates the crash in our reproduction scenario (before: instant exit on every canvas click under load; after: stable across repeated runs).
Source: makepad/makepad