Closed Bug 1925684 Opened 2 years ago Closed 6 months ago

Crash in [@ mozilla::widget::WlCompositorCrashHandler]

Categories

(Core :: Widget: Gtk, defect, P3)

All
Linux
defect

Tracking

()

RESOLVED FIXED
152 Branch
Tracking Status
firefox-esr115 --- unaffected
firefox-esr140 --- wontfix
firefox148 --- wontfix
firefox149 --- wontfix
firefox150 --- wontfix
firefox151 --- wontfix
firefox152 --- fixed

People

(Reporter: mccr8, Assigned: sinker)

References

(Blocks 1 open bug)

Details

(Keywords: crash)

Crash Data

Attachments

(1 external file)

Crash report: https://crash-stats.mozilla.org/report/index/e2114670-8251-4bee-8de9-1650b0241018

MOZ_CRASH Reason:

Compositor crashed (kde) proxy: WP:E WP:CA WP:CR WP:CPCA WP:CPCF

Top 10 frames:

0  libxul.so  MOZ_Crash(char const*, int, char const*)  mfbt/Assertions.h:317
0  libxul.so  mozilla::widget::WlCompositorCrashHandler()  widget/gtk/nsWaylandDisplay.cpp:534
1  libxul.so  WaylandProxy::CompositorCrashed()  third_party/wayland-proxy/wayland-proxy.cpp:996
1  libxul.so  ProxiedConnection::ProcessFailure()  third_party/wayland-proxy/wayland-proxy.cpp:579
2  libxul.so  WaylandProxy::ProcessConnections()  third_party/wayland-proxy/wayland-proxy.cpp:842
3  libxul.so  WaylandProxy::Run()  third_party/wayland-proxy/wayland-proxy.cpp:866
4  libxul.so  WaylandProxy::RunProxyThread(WaylandProxy*)  third_party/wayland-proxy/wayland-proxy.cpp:892
5  firefox-bin  set_alt_signal_stack_and_start(PthreadCreateParams*)  mozglue/interposers/pthread_create_interposer.cpp:81
6  libc.so.6  start_thread  /usr/src/debug/glibc-2.40/nptl/pthread_create.c:447
7  libc.so.6  __clone3  /usr/src/debug/glibc-2.40/sysdeps/unix/sysv/linux/x86_64/clone3.S:78

The first instance of this crash I see is in the 20241011104937 Nightly build.

That's expected, we added this handler specially for this case. It means Wayland compositor crashed so we can't continue. It's not a bug on our side.

Priority: -- → P3

We moved compositor crashes from Bug 1890074 to this one.

See Also: → 1890074

The bug is linked to a topcrash signature, which matches the following criterion:

  • Top 10 desktop browser crashes on nightly

For more information, please visit BugBot documentation.

Keywords: topcrash

The crash stat is:

1 	Compositor crashed (gnome) proxy: WP:E WP:CA WP:CR WP:CPCA WP:CPCF 	56 	48.28 %
2 	Compositor crashed (hyprland) proxy: WP:E WP:CA WP:CR WP:CPCA WP:CPCF 	18 	15.52 %
3 	Compositor crashed (ubuntu:gnome) proxy: WP:E WP:CA WP:CR WP:CPCA WP:CPCF 	16 	13.79 %
4 	Compositor crashed (kde) proxy: WP:E WP:CA WP:CR WP:CPCA WP:CPCF 	13 	11.21 %
5 	Compositor crashed (niri) proxy: WP:E WP:CA WP:CR WP:CPCA WP:CPCF 	4 	3.45 %
6 	Compositor crashed () proxy: WP:E WP:CA WP:CR WP:CPCA WP:CPCF 	3 	2.59 %
7 	Compositor crashed (kde) proxy: WP:E WP:CA WP:CR WP:CPCF WP:CPSF 	2 	1.72 %
8 	Compositor crashed (labwc:wlroots) proxy: WP:E WP:CA WP:CR WP:CPCA WP:CPCF 	2 	1.72 %
9 	Compositor crashed (ubuntu:gnome) proxy: WP:E WP:CA WP:CR WP:ACT WP:CPCA WP:CPCF 	1 	0.86 %
10 	Compositor crashed (zorin:gnome) proxy: WP:E WP:CA WP:CR WP:CPCA WP:CPCF 

WP:E WP:CA WP:CR WP:CPCA WP:CPCF means wayland proxy operates correctly as we expected and the failure is on Wayland compositor side.

The bug is linked to a topcrash signature, which matches the following criterion:

  • Top 10 desktop browser crashes on nightly (startup)

For more information, please visit BugBot documentation.

Based on the topcrash criteria, the crash signature linked to this bug is not a topcrash signature anymore.

For more information, please visit BugBot documentation.

This is the current Linux topcrasher.

Severity: -- → S2
OS: Unspecified → Linux
Hardware: Unspecified → All
Version: unspecified → Trunk

(In reply to Martin Stránský [:stransky] (ni? me) from comment #5)

WP:E WP:CA WP:CR WP:CPCA WP:CPCF means wayland proxy operates correctly as we expected and the failure is on Wayland compositor side.

Is this by any means actionable on our side then ?

Flags: needinfo?(stransky)

No, it's bug on system component which crashes. We can't do anything about it.

Flags: needinfo?(stransky)
Crash Signature: [@ mozilla::widget::WlCompositorCrashHandler] → [@ mozilla::widget::WlCompositorCrashHandler] [@ <name omitted> | mozilla::widget::WlCompositorCrashHandler ]

Note that this is by far the top crasher according to crash pings (whereas crash reports don't show many): https://crash-pings.mozilla.org/#kmsWOu

Duplicate of this bug: 2010155
Duplicate of this bug: 2010154
Duplicate of this bug: 2010153

Crash ID: 3b279680-c310-4199-8a52-583570260120
Signature: [@ mozilla::widget::WlCompositorCrashHandler ]

Crash ID: 814ab7cc-29ee-4365-b38c-60a3e0260120
Signature: [@ mozilla::widget::WlCompositorCrashHandler ]

(In reply to Martin Stránský [:stransky] (ni? me) (PTO till Feb 21) from comment #10)

No, it's bug on system component which crashes. We can't do anything about it.

Take this with a grain of AI salt, but there might be something we can do:

Looking at the code, there's no distinction between an actual compositor crash and a normal Wayland session logout/shutdown. Both follow the same path to MOZ_CRASH.

The detection logic is in ProxiedConnection::ProcessFailure() (https://searchfox.org/mozilla-central/source/third_party/wayland-proxy/wayland-proxy.cpp#596-619):

The proxy detects that reads/writes to the compositor socket have failed (mCompositorFailed)
After a timeout of CLOCKS_PER_SEC (https://searchfox.org/mozilla-central/source/third_party/wayland-proxy/wayland-proxy.cpp#169), it checks if the Wayland display socket file still exists via stat(mWaylandDisplay) (https://searchfox.org/mozilla-central/source/third_party/wayland-proxy/wayland-proxy.cpp#608)
If the socket is gone, it calls WaylandProxy::CompositorCrashed() which triggers WlCompositorCrashHandler() and MOZ_CRASH (https://searchfox.org/mozilla-central/source/widget/gtk/nsWaylandDisplay.cpp#1050-1057)
When a user logs out of a Wayland session, the compositor shuts down and removes the socket file ($XDG_RUNTIME_DIR/wayland-0), which looks identical to a compositor crash from this code's perspective.

Firefox does handle SIGTERM on the main thread (https://searchfox.org/mozilla-central/source/widget/gtk/nsAppShell.cpp#413-419), which session managers send during logout. However, the wayland-proxy runs on its own thread (https://searchfox.org/mozilla-central/source/third_party/wayland-proxy/wayland-proxy.cpp#925) with no communication channel back from the main thread. So the proxy can detect the compositor socket disappearing and MOZ_CRASH before the main thread even processes the SIGTERM quit event.

Firefox also listens for PrepareForSleep on org.freedesktop.login1 (https://searchfox.org/mozilla-central/source/widget/gtk/nsAppShell.cpp#204) but not for PrepareForShutdown.

It might be worth exploring our options here. Surely the Wayland proxy should do some AppShutdown::IsInOrBeyond check and avoid crashing if we are shutting down. Maybe we could also listen for PrepareForShutdown or other freedesktop events, similar to what we do on Windows where Firefox handles WM_QUERYENDSESSION and WM_ENDSESSION. Note:

The model is different from Windows. In systemd/login1:

  • Proactive inhibitor locks (instead of query/response): An application calls org.freedesktop.login1.Manager.Inhibit(what="shutdown", mode="delay", ...) before any shutdown is requested. This returns a file descriptor — as long as it's held open, systemd will delay (not block) shutdown.
  • PrepareForShutdown(true) fires when shutdown is initiated — this is the signal to do final cleanup and release the inhibitor lock.
  • Once all delay-type inhibitor locks are released (or InhibitDelayMaxSec expires, default 5 seconds), systemd proceeds with the actual shutdown.

So the mapping is roughly:

  • WM_QUERYENDSESSION (can I shut down?) → No direct equivalent. Instead you hold an inhibitor lock proactively, and systemd respects it up to a timeout.
  • WM_ENDSESSION (shutdown is happening) → PrepareForShutdown(true)

Note also that on X11 the situation seems to be less a problem as we do not crash on session shutdown, at least.

Flags: needinfo?(thinker.li)

AFAIK, the session manager usually wait for a few seconds after sending out SIGTERM. Then, it starts to shutdown the compositor. So, I wounder it can take that long to shutdown Firefox. But, exceptions are always there.

It would be better to remove the connection by return true here [1] instead of crashing Firefox since destroying socket is a part of normal procedure of shutdown or logout.

[1] https://hg-edge.mozilla.org/mozilla-central/file/a2e1e113ada9c857ff4cff0c79b58c6770b7dd7b/third_party/wayland-proxy/wayland-proxy.cpp#l610

Flags: needinfo?(thinker.li)

Further investigation into the codebase reveals that the disappearance of the Wayland compositor’s named socket—whether due to a compositor crash or a session logout—currently triggers a MOZ_CRASH. Firefox should instead shut down gracefully. While closing all proxy sockets seems like the logical step when they break, doing so triggers a known GLib crash (see Bug 1890074). To bypass this, I propose that WaylandProxy cease message forwarding and instead schedule a QUIT event on the main thread to initiate a clean shutdown.

When the WaylandProxy detects that the compositor socket has disappeared
(stat() fails on the display path), both compositor crash and normal
Wayland logout produce identical observable state: the socket file is
unlinked in both cases, so no reliable distinction between the two is
possible.

The previous approach called MOZ_CRASH via a CompositorCrashHandler
callback, producing crash reports under WlCompositorCrashHandler. This
made Bug 1925684 the #1 Linux crasher, but nearly all reports were false
positives from normal logouts rather than real compositor crashes.

The fundamental issue is that crashing is the wrong response in either
case. Whether the compositor crashed or the session ended, Firefox cannot
render anything further and should exit cleanly. MOZ_CRASH generates a
misleading minidump that blames Firefox for an external event.

This patch changes the behavior as follows:

  1. When stat() fails, WaylandProxy::CompositorUnavailable() is called.
    It sets a sCompositorGone flag and invokes a registered handler.

  2. ProcessConnections() checks sCompositorGone at the top of every
    cycle. When set, it drains and discards all pending data from each
    application socket instead of forwarding it. This prevents socket
    buffer backpressure: if nobody reads from application sockets the
    kernel buffers fill, clients' writes stall with EAGAIN, and if
    libwayland's send queue overflows it reports a protocol error that
    GDK logs and HandleGLibMessage turns into a crash.

  3. All application sockets are kept open throughout. GTK never observes
    a broken pipe and never fires a HandleGLibMessage crash.

  4. AddToPollFd() and LoadPollFd() skip compositor socket entries
    entirely when the compositor is gone. Both functions advance their
    pollfd pointer by the same amount so they stay in sync. nfds_max
    is sized accordingly. This avoids polling dead sockets whose
    persistent POLLERR/POLLHUP would otherwise cause poll() to spin
    and consume 100% CPU.

  5. No new proxy connections are accepted once the compositor is gone,
    since there is no compositor to back them.

  6. If multiple ProxiedConnections exist (one per Firefox process), they
    all share the same compositor display path. Once one detects the
    compositor is gone the flag applies to all of them instantly, without
    each connection waiting out its own sFailureTimeout.

  7. The handler (WlCompositorUnavailableHandler) dispatches to the main
    thread via NS_DispatchToMainThread and calls
    nsIAppStartup::Quit(eAttemptQuit). This is a normal, cancellable
    shutdown that allows Firefox to save the session and clean up.

  8. The proxy Run() loop continues polling IsChildAppTerminated(). When
    Firefox finishes shutting down, waitpid() returns and the proxy
    thread exits cleanly, closing all sockets naturally.

The CompositorCrashHandler typedef and related infrastructure have been
renamed to CompositorUnavailableHandler to reflect the corrected
semantics.

Assignee: nobody → thinker.li
Status: NEW → ASSIGNED
Attachment #9546303 - Attachment description: Bug 1925684 [Wayland] Gracefully quit when compositor is unavailable r=emilio → Bug 1925684 [Wayland] Gracefully quit when compositor is unavailable r?emilio

I haven't looked at patch details but can we just get PID of compositor from the socket we're connected to and check the compositor process is present?

Also I tested the logout scenario on Gnome and I haven't seen any Firefox crashes due to closed connections but rather just Firefox quit. Maybe different IDE's have different logout mechanism?

(In reply to Martin Stránský [:stransky] (ni? me) from comment #29)

I haven't looked at patch details but can we just get PID of compositor from the socket we're connected to and check the compositor process is present?

I can foresee that it could be blocked by containers if there are.

Also I tested the logout scenario on Gnome and I haven't seen any Firefox crashes due to closed connections but rather just Firefox quit. Maybe different IDE's have different logout mechanism?

Usually, firefox should receive SIGTERM before this case happen. However, the runnable handling SIGTERM could be pending on the queue of the main thread if the main thread is very busy.

(In reply to Thinker Li [:sinker] from comment #30)

(In reply to Martin Stránský [:stransky] (ni? me) from comment #29)

I haven't looked at patch details but can we just get PID of compositor from the socket we're connected to and check the compositor process is present?

I can foresee that it could be blocked by containers if there are.

Let's use compositor PID firts and then fallback to any other solution then. The PID may be the most reliable one.

Also I tested the logout scenario on Gnome and I haven't seen any Firefox crashes due to closed connections but rather just Firefox quit. Maybe different IDE's have different logout mechanism?

Usually, firefox should receive SIGTERM before this case happen. However, the runnable handling SIGTERM could be pending on the queue of the main thread if the main thread is very busy.

Firefox uses direct signal handler outside of any thread.
https://searchfox.org/firefox-main/rev/0894e095dfb46b6dac785365432791a54861fe09/toolkit/profile/nsProfileLock.cpp#123

SIGTERM does emergency quit - it just saves recent profile / removes profile lock and terminates immediately.

Duplicate of this bug: 2024550

Copying crash signatures from duplicate bugs.

Crash Signature: [@ mozilla::widget::WlCompositorCrashHandler] [@ <name omitted> | mozilla::widget::WlCompositorCrashHandler ] → [@ mozilla::widget::WlCompositorCrashHandler] [@ <name omitted> | mozilla::widget::WlCompositorCrashHandler ] [@ libxul.so (deleted) | libxul.so (deleted) | libxul.so (deleted) | libxul.so (deleted) | libxul.so (deleted) | set_alt_signal_stack_and_start]

This signature has been amplifying significantly since Fx150 release, and the crash-ping data is sharp enough that it's worth flagging here while this patch is awaiting review (note that crash-stats data is not showing this spike at all).

Linux release crash-ping shares (~80K Linux pings/day, opt-out):

                              Apr 13-20    Apr 27-May 04
                              (Fx149.x)    (Fx150.x)
WlCompositorCrashHandler        3.96%        7.31%
HandleGLibMessage               5.61%        8.42%

Both are signatures this patch directly targets: the MOZ_CRASH path, and the libwayland/GDK->GLib log path that the patch description (point 2) explicitly addresses by draining application sockets.

The growth is heavily concentrated on kernel 7.0 (Ubuntu 26.04 LTS, plus rolling distros that picked it up - Arch, CachyOS).

WlCompositorCrashHandler share within kernel-7.0 crashes:

Apr 20 (Fx149.x)       8.3%
Apr 23 (Fx150.0 GA)    9.1%
Apr 27 (Fx150.0)      25.7%
Apr 30 (Fx150.0/0.1)  21.6%
May 02 (Fx150.0.1)    20.9%
May 04 (Fx150.0.1)    19.8%

That's a per-user rate jump locked to the Fx150 rollout - kernel-7.0 population growth (Ubuntu 26.04 LTS, ~7x share growth in 2 weeks) compounds it but isn't the cause.

Likely amplifier: Bug 1940341 (also in 150) removed the transient-error retry block from ConnectToCompositor() (EAGAIN/ECONNREFUSED/EINPROGRESS/... used to retry up to 100x, now any failure -> mCompositorFailed -> straight to ProcessFailure()). On rolling distros with more frequent compositor restarts, that brief window where the socket file is gone is now caught much more often - exactly the path this patch fixes.

Proto-signature is unchanged Fx149->Fx150 (~95% go via ProxiedConnection::ProcessFailure -> WaylandProxy::CompositorCrashed), so no new code path; just the same path firing 2-3x more often.

This patch would eliminate the WlCompositorCrashHandler signature (graceful Quit instead of MOZ_CRASH), and mitigate the HandleGLibMessage co-spike via the application-socket drain.

It wouldn't address the root cause from 1940341 (Firefox concluding compositor-gone too eagerly on transient errors), but it would correctly handle the case where the compositor really did go away, which is what this bug is for.

We may also want a follow up for bug 1940341 to mitigate its impact a bit (retry differently was an option already there, IIUC) ?

Crash Signature: [@ mozilla::widget::WlCompositorCrashHandler] [@ <name omitted> | mozilla::widget::WlCompositorCrashHandler ] [@ libxul.so (deleted) | libxul.so (deleted) | libxul.so (deleted) | libxul.so (deleted) | libxul.so (deleted) | → [@ mozilla::widget::WlCompositorCrashHandler] [@ <name omitted> | mozilla::widget::WlCompositorCrashHandler ] [@ libxul.so (deleted) | libxul.so (deleted) | libxul.so (deleted) | libxul.so (deleted) | libxul.so (deleted) |
Flags: needinfo?(thinker.li)
Flags: needinfo?(stransky)
Flags: needinfo?(emilio)

Sure, will review the patch. I think should watch compositor PID there. I can update the patch if needed, depends on Thinker Li.

Flags: needinfo?(stransky)
Flags: needinfo?(emilio)

I will update the patch.

Flags: needinfo?(thinker.li)

(In reply to Martin Stránský [:stransky] (ni? me) from comment #31)

(In reply to Thinker Li [:sinker] from comment #30)

(In reply to Martin Stránský [:stransky] (ni? me) from comment #29)

I haven't looked at patch details but can we just get PID of compositor from the socket we're connected to and check the compositor process is present?

I can foresee that it could be blocked by containers if there are.

Let's use compositor PID firts and then fallback to any other solution then. The PID may be the most reliable one.

I need a clarification. What do you suggest here for the case the compositor is still alive or gone?
If the compositor is alive, that mean logging out or someone close the connection and remove the named socket.
If the compositor is dead, that mean the compositor is killed or crash.
Should we handle them differently?
I would expect to exit gracefully for both case.

Flags: needinfo?(stransky)

(In reply to Thinker Li [:sinker] from comment #37)

I need a clarification. What do you suggest here for the case the compositor is still alive or gone?
If the compositor is alive, that mean logging out or someone close the connection and remove the named socket.

If the compositor is alive and we're disconnected, then there's a protocol error and we were disconnected due of it.
We can keep proxy some time to make sure it's really only client termination and not session quit
(not sure how to get session quit? Via DBus or so?)
If we're disconnected due to protocol error, it's Firefox fault and we should issue crash handler to get info about it.

If the compositor is dead, that mean the compositor is killed or crash.

Yes, so it's compositor fault and we can't do nothing. Ignore the error then, just quit.

Flags: needinfo?(stransky)

(In reply to Martin Stránský [:stransky] (ni? me) from comment #38)

(In reply to Thinker Li [:sinker] from comment #37)

I need a clarification. What do you suggest here for the case the compositor is still alive or gone?
If the compositor is alive, that mean logging out or someone close the connection and remove the named socket.

If the compositor is alive and we're disconnected, then there's a protocol error and we were disconnected due of it.
We can keep proxy some time to make sure it's really only client termination and not session quit
(not sure how to get session quit? Via DBus or so?)
If we're disconnected due to protocol error, it's Firefox fault and we should issue crash handler to get info about it.

Firefox should receive a wl_display.error message and crash in WlLogHandler for a protocol error. Previously, we have added a bunch of WlLogHandler_* functions. Protocol errors should not end up here. I notice one except, WlLogHandler ignore still attached errors. Adding this error to the crash reason or sending a telemetry ping may help. By the way, WaylandProxy already waits for 1s before crash.

I checked the history of WaylandProxy. It was landed to mitigate buffer overflow at the compositor side. In this case, Firefox doesn't receive wl_display.error since the server side buffer is full. The bug here is pretty much a similar root cause. For this case, it is better to send a telemetry ping and exit gracefully. WDYT?

Flags: needinfo?(stransky)

Just found one fact that a wl_display.error message may wait in the queue of a WaylandProxy if the main thread is too busy to read the application socket and the kernel buffer of the socket is full. Once WaylandProxy find that a compositor socket is closed, it stops flushing the corresponding application socket. Messages in the output queue of the application socket will never be sent. When this happen, it may cause this bug or bug 1890074.

If WaylandProxy keep flushing the application socket even it's associated compositor socket is closed, the main thread will receive wl_display.error messages and crash in WlLogHandler instead. Then, we can category them according to crash reasons.

Attachment #9546303 - Attachment description: Bug 1925684 [Wayland] Gracefully quit when compositor is unavailable r?emilio → Bug 1925684 [Wayland] Keep draining and flushing the application socket after compositor disconnect r=emilio
Flags: needinfo?(stransky)
See Also: → 2036078
Attachment #9546303 - Attachment description: Bug 1925684 [Wayland] Keep draining and flushing the application socket after compositor disconnect r=emilio → Bug 1925684 [Wayland] Gracefully quit when compositor is unavailable r=emilio
Status: ASSIGNED → RESOLVED
Closed: 6 months ago
Resolution: --- → FIXED
Target Milestone: --- → 152 Branch

Since the bug is closed, the stalled keyword is now meaningless.
For more information, please visit BugBot documentation.

Keywords: stalled

Since nightly and release are affected, beta will likely be affected too.
For more information, please visit BugBot documentation.

QA Whiteboard: [qa-triage-done-c153/b152]

This could probably use a Release uplift request.

Flags: needinfo?(thinker.li)

(In reply to Ryan VanderMeulen [:RyanVM] from comment #45)

This could probably use a Release uplift request.

This is long lasting issue although it is a s2 bug. I will skip the release uplift.

Flags: needinfo?(thinker.li)
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: