Don't lose the session when an output is missing from the workspace sets - #2839
Don't lose the session when an output is missing from the workspace sets#2839dev-goalz wants to merge 1 commit into
Conversation
|
The PR template is required. Please add it back and complete the checklist. |
|
Adding the capture behind the "How it was checked" note, since a reasoned argument The build under test carried this patch plus a diagnostic that logs the miss instead The recorded line: That is the unguarded call inside the layer-map guard in Immediately after: same process, every surface thread alive, no panic anywhere in the It has kept happening since, and kept being absorbed: Four in five and a half weeks of ordinary use, with the session surviving each one. Two caveats so this is not read as more than it is. It is one machine, and the |
…ace sets Makes the Workspaces lookups total and re-points seats that name a removed output. Written with assistance from Claude Opus 5.0. Reviewed, built and tested by the author, who understands the changes in full.
048d9b2 to
e639bb2
Compare
Done |
Switching a monitor off, or a dock dropping its link, can currently take down the
whole COSMIC session and every open window with it. The worst part is the delay. The
session usually keeps running for minutes or hours after the display change that
broke it, so the crash looks like it was caused by whatever you happened to be doing
at the time. On one machine here the gap between cause and crash reached 23 hours.
What happens is that an output's render thread asks about workspaces for an output
the main thread has just removed. On a laptop the common case is the built in panel
being switched off because the lid is closed, while its own render thread is still
finishing a frame.
active_numunwraps that lookup instead of handling the miss, sothe thread panics. The panic poisons a lock on its way out, and the compositor then
aborts at the next display operation, whenever that happens to be.
This makes the three
Workspaceslookups total instead of partial, the wayactiveand
active_mutalready are.idx_for_handleandlenhad nobackup_setfallbackat all. It also moves one call out from under the layer map guard so that a panic
there cannot poison it, and fixes a double unwrap on the same accessor in the image
capture path.
Two further sites reach the same lookups through a seat rather than through the
render loop, and neither is covered by the
backup_setfallback. A seat keeps itsown idea of which output is focused or active, and that field is never checked
against
sets. When the last output goes away the fallback stores the workspace setaside and the seat fix ups are skipped, so every seat still names an output that no
longer exists.
update_activethen unwrapsactive_spaceon it and aborts on themain thread, with no delay and no poisoned lock, which is a different failure from
the one above but the same root cause.
Rather than harden each consumer,
add_outputnow restores the invariant. When ittakes the stored set back it re points any seat that still names an output which is
no longer present. That covers the sites in this PR and any future caller that
trusts a seat's output, which is what the rest of the code already assumes it can do.
A surface on its way out asking about workspaces that are already gone is now a no-op
instead of a session ending abort. The worst case after this is one frame of layer
shell surfaces tagged with workspace zero, on an output that is being torn down
anyway.
How it was checked
Running on one laptop with an external display on USB-C since 2026-08-31. In that
time the guarded lookup absorbed four faults that would each have aborted the
compositor on an unpatched build, the most recent on 2026-09-07, and the session
survived all of them with the same process still running. Before the patches the
same machine lost its session ten times.
Relates to #2727.
Written with assistance from Claude Opus 5.0, as disclosed in the commit message.
The changes were reviewed, built and run on a daily driver for five and a half
weeks before submitting, and I can answer review comments on any of it.