Skip to content

fix: exit gracefully when the display server connection is lost - #52603

Merged
ckerr merged 6 commits into
mainfrom
linux-ozone-shutdown
Aug 7, 2026
Merged

ckerr merged 6 commits into
mainfrom
linux-ozone-shutdown

Conversation

@codebytere

@codebytere codebytere commented Aug 3, 2026 •

Copy link
Copy Markdown
Member

Description of Change

On Linux the Ozone platform runs the browser-provided shutdown callback when the X11/Wayland connection breaks (X server exit, session logout, compositor restart). Ours went straight to LOG(FATAL), so every display-server teardown produced a crash report. Chrome's equivalent runs chrome::SessionEnding() first and only fatals if that fails to end the process.

Add Browser::ExitWithCode() (the app.exit() path, callable from native code), have the callback force-exit like app.exit(0), and keep the fatal as a 10-second delayed watchdog for the case where exiting hangs.

Checklist

  • PR description included and stakeholders cc'd
  • npm test passes
  • tests are changed or added
  • relevant documentation, tutorials, templates and examples are changed or are not needed

Release Notes

Notes: Fixed a crash report when the X server or Wayland compositor exits while an app is running.

@codebytere codebytere added semver/patch backwards-compatible bug fixes target/42-x-y PR should also be added to the "42-x-y" branch. target/43-x-y PR should also be added to the "43-x-y" branch. target/44-x-y PR should also be added to the "44-x-y" branch. labels Aug 3, 2026
@electron-cation electron-cation Bot added the new-pr 🌱 PR opened recently label Aug 3, 2026
The Ozone shutdown callback that runs when the X11/Wayland connection
breaks went straight to LOG(FATAL), so every X server exit or
compositor restart produced a crash report. Add
Browser::ExitWithCode() (the app.exit() path, callable from native
code), have the callback force-exit like app.exit(0), and keep the
FATAL as a 10-second delayed watchdog in case exiting hangs.
@codebytere
codebytere force-pushed the linux-ozone-shutdown branch from d00223b to f913bf3 Compare August 3, 2026 03:01

@jkleinsc jkleinsc left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#52603 (review) needs to be addressed.

@codebytere
codebytere requested a review from deepak1556 August 3, 2026 16:11
@codebytere
codebytere requested a review from jkleinsc August 3, 2026 18:41

@jkleinsc jkleinsc left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like there is a compile error:
The build fails in shell/browser/electron_browser_main_parts.cc with:

error: only virtual member functions can be marked 'override'
      void Alarm() override { LOG(FATAL) << "Failed to shutdown."; }

This PR adds a local ShutdownWatchdog class that subclasses base::Watchdog and overrides Alarm():

class ShutdownWatchdog : public base::Watchdog {
 public:
  ShutdownWatchdog()
      : base::Watchdog(base::Seconds(10), "OzoneShutdown", true) {}
  void Alarm() override { LOG(FATAL) << "Failed to shutdown."; }
};

But, base::Watchdog::Alarm() (base/threading/watchdog.h) is not virtual — only base::Watchdog::Delegate::Alarm() is:

class BASE_EXPORT Watchdog {
 public:
  class Delegate {
   public:
    virtual ~Delegate() = default;
    virtual void Alarm() = 0;   // <- this is the virtual one
  };
  ...
  void Alarm();   // <- non-virtual, dispatches to delegate_->Alarm() or DefaultAlarm()

In base/threading/watchdog.cc:

void Watchdog::Alarm() {
  if (delegate_) {
    delegate_->Alarm();
  } else {
    DefaultAlarm();
  }
}

So subclassing Watchdog and redefining Alarm() just hides the base method (and would never actually be invoked by the watchdog thread) — hence the compiler correctly rejects override since there's no virtual base method being overridden.

Suggested Fix

Instead of subclassing base::Watchdog, implement base::Watchdog::Delegate and pass it into the Watchdog constructor's delegate parameter:

auto shutdown_cb = base::BindOnce([] {
  class ShutdownWatchdogDelegate : public base::Watchdog::Delegate {
   public:
    void Alarm() override { LOG(FATAL) << "Failed to shutdown."; }
  };
  static base::NoDestructor<ShutdownWatchdogDelegate> delegate;
  static base::NoDestructor<base::Watchdog> watchdog(
      base::Seconds(10), "OzoneShutdown", /*enabled=*/true, delegate.get());
  watchdog->Arm();
  if (Browser* browser = Browser::Get())
    browser->ExitWithCode(content::RESULT_CODE_NORMAL_EXIT);
  else
    LOG(FATAL) << "Failed to shutdown.";
});

This uses the delegate pattern base::Watchdog actually supports for custom alarm behavior, rather than trying to override a non-virtual method.

@ckerr ckerr left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 on John's analysis wrt using the delegate if we need Alarm() to be fatal.

I'm not 100% sure though, does Alarm() need to be fatal? If so, John's suggestion is the one to use. If not, ...maybe we just remove the breaking Alarm() override call?

@codebytere
codebytere requested review from ckerr and jkleinsc August 4, 2026 01:46

@deepak1556 deepak1556 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@electron-cation electron-cation Bot removed the new-pr 🌱 PR opened recently label Aug 4, 2026
@codebytere
codebytere dismissed jkleinsc’s stale review August 7, 2026 00:17

Changes addressed

@ckerr
ckerr merged commit e752ef4 into main Aug 7, 2026
72 checks passed
@ckerr
ckerr deleted the linux-ozone-shutdown branch August 7, 2026 03:17
@release-clerk

release-clerk Bot commented Aug 7, 2026

Copy link
Copy Markdown

Release Notes Persisted

Fixed a crash report when the X server or Wayland compositor exits while an app is running.

@trop

trop Bot commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

I have automatically backported this PR to "44-x-y", please check out #52684

@trop trop Bot added the in-flight/44-x-y label Aug 7, 2026
@trop

trop Bot commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

I have automatically backported this PR to "43-x-y", please check out #52685

@trop trop Bot removed the target/44-x-y PR should also be added to the "44-x-y" branch. label Aug 7, 2026
@trop

trop Bot commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

I have automatically backported this PR to "42-x-y", please check out #52686

@trop trop Bot added in-flight/43-x-y in-flight/42-x-y merged/42-x-y PR was merged to the "42-x-y" branch. merged/44-x-y PR was merged to the "44-x-y" branch. merged/43-x-y PR was merged to the "43-x-y" branch. and removed target/43-x-y PR should also be added to the "43-x-y" branch. target/42-x-y PR should also be added to the "42-x-y" branch. in-flight/42-x-y in-flight/44-x-y in-flight/43-x-y labels Aug 7, 2026
MarshallOfSound pushed a commit that referenced this pull request Sep 24, 2026
Second batch of specs for fixes that landed without one, each checked to
fail on the nightly release before the fix and pass after it:

- child processes forked from the zygote carry their own process title
  (#50509)
- the app exits instead of hitting LOG(FATAL) when the X server goes
  away (#52603), using a private Xvfb picked with -displayfd
- a fully transparent titleBarOverlay colour is honoured (#51017)
- the titleBarOverlay and its caption buttons are drawn on Linux
  (#52577)
- transparent frameless windows get no border painted around them
  (#50541)

The last three read pixels back off the X screen through a new
captureDisplayPixels() helper that compares captured colours with each
other rather than with constants, so it holds up on the 16-bit Xvfb
screen CI uses.
MarshallOfSound pushed a commit that referenced this pull request Sep 24, 2026
Regression test for #52603, where losing the display server connection
went straight to LOG(FATAL). The spec starts a private Xvfb (skipping if
none is available), launches a fixture app on it that logs when its window
is ready and when 'quit' is emitted, kills the X server and expects the
app to emit 'quit' and exit normally rather than die on a signal.

Verified against Linux release builds: the app dies with SIGTRAP on
45.0.0-nightly.20260805 and exits cleanly on 45.0.0-nightly.20260808.
MarshallOfSound pushed a commit that referenced this pull request Sep 24, 2026
Regression test for #52603, where losing the display server connection
went straight to LOG(FATAL). The spec starts a private Xvfb (skipping if
none is available), launches a fixture app on it that logs when its window
is ready, kills the X server and expects the app to exit with a normal
exit code rather than die on a signal. Either Ozone (the app.exit(0) path
the fix added) or GTK (_exit(1)) can be the first to notice the dead
connection, so both codes are accepted. The X server is started inside the
test so mocha's in-job retries get a fresh one.

Verified against Linux release builds: the app dies with SIGTRAP on
45.0.0-nightly.20260805 and exits cleanly on 45.0.0-nightly.20260808.
MarshallOfSound added a commit that referenced this pull request Sep 24, 2026
* test: cover app.disableHardwareAcceleration() adding --disable-gpu

Regression test for #51817, where disableHardwareAcceleration() stopped
appending the --disable-gpu switch. A small fixture app calls it before
ready and reports whether app.commandLine has the switch once ready.

Verified against Linux release builds: fails on 45.0.0-nightly.20260716,
passes on 45.0.0-nightly.20260720.

* test: check the default menu has no Help menu

Regression test for #50629, which moved the Electron project links out of
the menu every app gets by default and into the default app. The
default-menu fixture gains a --print-items mode that prints the roles and
labels of the top-level items, and the spec asserts the window menu is
there but no Help menu is.

Verified against Linux release builds: fails on 43.0.0-nightly.20260408,
passes on 43.0.0-nightly.20260413.

* test: check an unopened Menu can be garbage collected

Regression test for #50806, where a Menu that was built but never opened
was kept alive forever. The spec drops the last reference, holds a WeakRef
and requests async GCs until it clears.

Verified against Linux release builds: fails on 43.0.0-nightly.20260408,
passes on 43.0.0-nightly.20260413.

* test: check openDevTools() ignores an unknown dock mode

Regression test for #50646, where the dock mode string was spliced into a
script evaluated in the DevTools frontend. The spec passes a mode that
would break out of the string literal and set a global, waits for the
frontend host to round-trip, and asserts the global was never set. Uses
its own session partition so the dock state it leaves behind does not leak
into other DevTools tests.

Verified against Linux release builds: fails on 43.0.0-nightly.20260402,
passes on 43.0.0-nightly.20260406.

* test: check DevTools reopens in its last dock state

Regression test for #50807, where calling openDevTools() without a mode
always docked to the right instead of restoring the previous dock state.
The spec opens DevTools undocked, closes it, reopens with no options and
reads currentDockState back from the frontend preferences.

Verified against Linux release builds: fails on 43.0.0-nightly.20260408,
passes on 43.0.0-nightly.20260413.

* test: check a running app keeps serving its original asar after replacement

Regression test for #52283. File contents used to be re-read from whatever
file was at the archive's path using offsets from the header read at
startup, so replacing app.asar under a running app (as updaters do) served
the wrong bytes or failed. A fixture app loads a file from a temporary
asar in a BrowserWindow, renames a different archive over it, loads the
same file again and reports both results; the spec expects them to match
the original archive. Skipped on Windows, which does not allow renaming
over an archive that is held open.

Verified against Linux release builds: fails on 45.0.0-nightly.20260706,
passes on 45.0.0-nightly.20260716.

* test: check zygote children get their own process title on Linux

Regression test for #50509, where processes forked from the zygote kept
the zygote's command line as their process title, so ps and friends
showed every child as --type=zygote. The spec reads /proc/<pid>/cmdline
for the GPU, renderer and utility processes reported by getAppMetrics()
and expects each to carry its own --type switch, tolerating processes
that exit in the meantime.

Verified against Linux release builds: fails on 43.0.0-nightly.20260323,
passes on 43.0.0-nightly.20260402.

* test: check losing the X server exits the app instead of crashing

Regression test for #52603, where losing the display server connection
went straight to LOG(FATAL). The spec starts a private Xvfb (skipping if
none is available), launches a fixture app on it that logs when its window
is ready, kills the X server and expects the app to exit with a normal
exit code rather than die on a signal. Either Ozone (the app.exit(0) path
the fix added) or GTK (_exit(1)) can be the first to notice the dead
connection, so both codes are accepted. The X server is started inside the
test so mocha's in-job retries get a fresh one.

Verified against Linux release builds: the app dies with SIGTRAP on
45.0.0-nightly.20260805 and exits cleanly on 45.0.0-nightly.20260808.

* test: check a fully transparent titleBarOverlay color on Linux

Regression test for #51017, where a fully transparent overlay colour was
treated as unset and replaced with the default opaque one. Adds
captureDisplayPixels()/expectDisplayPixelsEventually() screen helpers that
read the primary display back through desktopCapturer and retry a set of
assertions until the compositor catches up, then uses them to show a red
page under a transparent overlay and assert that nearly all of the overlay
strip shows the page (only the caption glyphs differ).

The page carries a marker square so the check cannot pass on an unpainted
or stale surface, and colours are compared against each other rather than
constants because CI's 16-bit Xvfb screen quantises them. X11 only:
Wayland has no portal-free capture and other platforms draw native
caption buttons. Tagged serial since it reads the real screen.

Verified against Linux release builds: fails on 44.0.0-nightly.20260529,
passes on 44.0.0-nightly.20260701.

* test: check titleBarOverlay draws its background and buttons on Linux

Regression test for #52577, where the caption button container was not
shown at all on Linux. Using the same capture helpers, the spec shows a
red page with a blue overlay and white symbols and asserts that the
overlay strip is mostly not the page colour and that a second colour (the
button glyphs) is present within it.

Verified against Linux release builds: fails on 45.0.0-nightly.20260731,
passes on 45.0.0-nightly.20260803.

* test: check transparent frameless windows draw no border on Linux

Regression test for #50541, where the frame painted an opaque border
around transparent frameless windows on Linux. The spec puts a blue
backdrop window across the work area, shows a transparent frameless
window with two marker squares over it, captures the screen and asserts
that the only colours in and just around the window bounds are the
backdrop, the see-through area and the two markers, i.e. no frame, border
or shadow pixels. X11 only, tagged serial with the rest of the
"transparent" suite.

Verified against Linux release builds: fails on 43.0.0-nightly.20260323,
passes on 43.0.0-nightly.20260402.

---------

Co-authored-by: Claude <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

45-x-y merged/42-x-y PR was merged to the "42-x-y" branch. merged/43-x-y PR was merged to the "43-x-y" branch. merged/44-x-y PR was merged to the "44-x-y" branch. semver/patch backwards-compatible bug fixes

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

5 participants