Linux: fix notification panic in notify-rust (nested zbus block_on) (#752) #756

Closed
charles wants to merge 0 commits from fix-752-linux-notification-panic into textchat
Owner

Closes #752

Cause. Not tokio. The issue's backtrace showed only its top frames; the full one (reproduced) is a nested block_on inside notify-rust: Notification::show → zbus::block_on(connect_and_send_notification) → while that future is polled, hints_to_map dereferences notify-rust's lazy SPEC_VERSION (needed to name the image-data hint, so only notifications with an icon) → get_server_information() → a second zbus::block_on on the same thread. zbus 6's runtime (zruntime 0.2.2) marks a thread that is driving a block_on (DRIVING thread-local) and panics on a nested one (InBlockOn::enter). This would happen on any thread, tokio or not. zbus 5 (async-io's block_on) allowed nesting; zbus 6.2.1 came in with 09ec9679 (2026-11-14), and the panics start on 2026-11-15. The panic also poisons the lazy_static, so every later notification with an icon would panic as well. In the app the worker (notify_worker, a spawn_blocking task) died with the panic: its receiver dropped, the icon task stopped forwarding, and every later notification in that run was lost without a log line.

Fix.

  • fluxer-platform (notify/linux.rs): right after the first successful GetCapabilities, outside any block_on, read *notify_rust::SPEC_VERSION once, so show never has to ask. A server that does not answer gets 1.1, as notify-rust already assumes.
  • apps/fluxer (runtime.rs): the notify worker runs each notification inside catch_unwind; a panic is logged as a WARN with its message and the worker goes on with the next one.
  • CI (Linux): installs dbus (for dbus-daemon), which the new test needs.

Verified.

  • New crates/fluxer-platform/tests/notify_session_bus.rs: a private dbus-daemon (minimal config, no service activation), a fake org.freedesktop.Notifications (GetCapabilities, GetServerInformation 1.2, Notify, CloseNotification, ActionInvoked for the click). A child process runs what notify_worker does: system_notifier on a multi-thread tokio runtime's spawn_blocking thread, two notifications with the 128 px avatar icon. Before the fix it panicked with the exact message from #752; after it, both are received with app name Flaxative, desktop-entry=flaxative, category, urgency, image-data and the default/Open action, and both clicks come back with their message ids. Also passes inside an ubuntu:22.04 container (dbus 1.12, the CI image).
  • New runtime::tests::a_notifier_that_panics_does_not_stop_the_worker: failed without the catch_unwind, passes with it.
  • A real notification on this machine's KDE Plasma 6.8.2 session bus (spec 1.2), sent from a tokio blocking thread: Plasma accepted it (id returned), and dbus-monitor showed app name Flaxative, desktop-entry flaxative, category im, the 128x128 image-data, and the default/Open action. It was closed with CloseNotification, and Plasma sent NotificationClosed (reason 3). Nobody clicked it, and nobody looked at the screen.
  • Windows does not use this code: notify/windows.rs calls tauri-winrt-notification directly, with no zbus. The worker change is platform-neutral and adds no cfg-specific imports.
  • FLUXER_SCREENSHOT_TESTS=1 cargo xtask ci: all steps passed.

Note. A caught panic still goes through the app's panic hook, so it still writes a panic-*.txt report. That is intended: it stays visible.

Also found while checking the other panic reports: #753 (a different, one-off UI panic in MessageList::layout).

🤖 Generated with Claude Code

Closes #752 **Cause.** Not tokio. The issue's backtrace showed only its top frames; the full one (reproduced) is a nested `block_on` inside notify-rust: `Notification::show` → `zbus::block_on(connect_and_send_notification)` → while that future is polled, `hints_to_map` dereferences notify-rust's lazy `SPEC_VERSION` (needed to name the `image-data` hint, so only notifications with an icon) → `get_server_information()` → a second `zbus::block_on` on the same thread. zbus 6's runtime (`zruntime` 0.2.2) marks a thread that is driving a `block_on` (`DRIVING` thread-local) and panics on a nested one (`InBlockOn::enter`). This would happen on any thread, tokio or not. zbus 5 (async-io's `block_on`) allowed nesting; zbus 6.2.1 came in with 09ec9679 (2026-11-14), and the panics start on 2026-11-15. The panic also poisons the `lazy_static`, so every later notification with an icon would panic as well. In the app the worker (`notify_worker`, a `spawn_blocking` task) died with the panic: its receiver dropped, the icon task stopped forwarding, and every later notification in that run was lost without a log line. **Fix.** - `fluxer-platform` (`notify/linux.rs`): right after the first successful `GetCapabilities`, outside any `block_on`, read `*notify_rust::SPEC_VERSION` once, so `show` never has to ask. A server that does not answer gets 1.1, as notify-rust already assumes. - `apps/fluxer` (`runtime.rs`): the notify worker runs each notification inside `catch_unwind`; a panic is logged as a WARN with its message and the worker goes on with the next one. - CI (Linux): installs `dbus` (for `dbus-daemon`), which the new test needs. **Verified.** - New `crates/fluxer-platform/tests/notify_session_bus.rs`: a private `dbus-daemon` (minimal config, no service activation), a fake `org.freedesktop.Notifications` (GetCapabilities, GetServerInformation 1.2, Notify, CloseNotification, `ActionInvoked` for the click). A child process runs what `notify_worker` does: `system_notifier` on a multi-thread tokio runtime's `spawn_blocking` thread, two notifications with the 128 px avatar icon. Before the fix it panicked with the exact message from #752; after it, both are received with app name `Flaxative`, `desktop-entry=flaxative`, `category`, `urgency`, `image-data` and the `default`/`Open` action, and both clicks come back with their message ids. Also passes inside an ubuntu:22.04 container (dbus 1.12, the CI image). - New `runtime::tests::a_notifier_that_panics_does_not_stop_the_worker`: failed without the `catch_unwind`, passes with it. - A real notification on this machine's KDE Plasma 6.8.2 session bus (spec 1.2), sent from a tokio blocking thread: Plasma accepted it (id returned), and `dbus-monitor` showed app name `Flaxative`, `desktop-entry` `flaxative`, `category` `im`, the 128x128 `image-data`, and the `default`/`Open` action. It was closed with `CloseNotification`, and Plasma sent `NotificationClosed` (reason 3). Nobody clicked it, and nobody looked at the screen. - Windows does not use this code: `notify/windows.rs` calls `tauri-winrt-notification` directly, with no zbus. The worker change is platform-neutral and adds no cfg-specific imports. - `FLUXER_SCREENSHOT_TESTS=1 cargo xtask ci`: all steps passed. **Note.** A caught panic still goes through the app's panic hook, so it still writes a `panic-*.txt` report. That is intended: it stays visible. Also found while checking the other panic reports: #753 (a different, one-off UI panic in `MessageList::layout`). 🤖 Generated with [Claude Code](https://claude.com/claude-code)
notify-rust reads the server's spec version into its lazy SPEC_VERSION the
first time a notification with an image-data hint is sent, from inside the
zbus::block_on of Notification::show. zbus 6's runtime (zruntime) refuses a
nested block_on on a thread already driving one and panics; the panic also
poisons the lazy value. Read it right after the capabilities query, outside
any block_on.

The notify worker now catches a notifier panic, logs a WARN and goes on, so a
failing notification no longer ends the worker and loses every later one.

Tests: tests/notify_session_bus.rs shows notifications with an icon from a
tokio spawn_blocking thread to a fake org.freedesktop.Notifications on a
private dbus-daemon (panicked before the fix); runtime test for a panicking
notifier. CI installs `dbus` for dbus-daemon.

Closes #752

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Author
Owner

Merged into textchat by hand (the merge API returns 405); the commits are in the branch.

Merged into `textchat` by hand (the merge API returns 405); the commits are in the branch.
charles closed this pull request 2026-11-16 07:32:26 +00:00

Pull request closed

Sign in to join this conversation.
No description provided.