Bug 425982

Summary: Session saving broken with KDE_APPLICATIONS_AS_SCOPE
Product: [Unmaintained] ksmserver Reporter: Ahmad Samir <a.samirh78>
Component: generalAssignee: David Edmundson <kde>
Status: RESOLVED FIXED    
Severity: normal CC: ahartmetz, hpj, kde, kishore96, nate, plasma-bugs-null, postix, vkrause
Priority: NOR    
Version First Reported In: unspecified   
Target Milestone: ---   
Platform: Other   
OS: Linux   
Latest Commit: Version Fixed/Implemented In:
Sentry Crash Report:
Attachments: .config/ksmserverrc

Description Ahmad Samir 2020-08-30 13:35:59 UTC
Session restore seems to be broken for KDE/Qt apps with KDE_APPLICATIONS_AS_SCOPE=1; since plasma-workspace exports that var unconditionally the only way to disable the KIO systemd integration is to hack SystemdProcessRunner::isAvailable() and make it always return false.

Note that restoring kde/qt apps is broken but restoring e.g. thunderbird/firefox seems to work.

Running a recent-ish git master snapshot.
Comment 1 David Edmundson 2020-08-30 21:15:18 UTC
Please can you be more precise with "broken"


What's broken? 
What version of frameworks?
Comment 2 Ahmad Samir 2020-08-30 22:49:41 UTC
Recent git master builds of the frameworks.

What's broken is that if I have say dolphin running, with "restore previous session" in kcmsmserver enabled, then log out, the dolphin window isn't restored when I log back in.

I think this part from the journal is relevant:
Aug 31 00:38:28 homeBox systemd[20069]: Created slice app.slice.
Aug 31 00:38:28 homeBox systemd[20069]: Starting app-org.kde.dolphin@9352ee02c9ba473d8d75232863751bbd.service...
[...]
Aug 31 00:38:31 homeBox dbus-daemon[20083]: [session uid=1002 pid=20083] Activating service name='org.kde.LogoutPrompt' requested by ':1.15' (uid=1002 pid=20201 comm="/usr/bin/plasmashell ")
Aug 31 00:38:31 homeBox dbus-daemon[20083]: [session uid=1002 pid=20083] Successfully activated service 'org.kde.LogoutPrompt'
[...]
Aug 31 00:38:33 homeBox dbus-daemon[20083]: [session uid=1002 pid=20083] Activating service name='org.kde.Shutdown' requested by ':1.11' (uid=1002 pid=20183 comm="/usr/bin/ksmserver ")
Aug 31 00:38:33 homeBox dbus-daemon[20083]: [session uid=1002 pid=20083] Successfully activated service 'org.kde.Shutdown'
[...]
Aug 31 00:38:33 homeBox sddm-helper[20067]: [PAM] Closing session
Aug 31 00:38:33 homeBox sddm-helper[20067]: pam_unix(sddm:session): session closed for user abc
Aug 31 00:38:33 homeBox sddm-helper[20067]: [PAM] Ended.
Aug 31 00:38:33 homeBox sddm[694]: Auth: sddm-helper exited successfully
Aug 31 00:38:33 homeBox sddm[694]: Socket server stopping...
Aug 31 00:38:33 homeBox sddm[694]: Socket server stopped.
Aug 31 00:38:33 homeBox sddm[694]: Display server stopping...
Aug 31 00:38:33 homeBox dolphin[20282]: The X11 connection broke (error 1). Did the X11 server die?
Aug 31 00:38:33 homeBox systemd[1]: Stopping Session 21 of user abc.
Aug 31 00:38:33 homeBox kded5[20157]: QDBusAbstractAdaptor: Cannot relay signal KDEDModule::moduleDeleted(KDEDModule*): Pointers are not supported: KDEDModule*
Aug 31 00:38:33 homeBox kglobalaccel5[20180]: The X11 connection broke (error 1). Did the X11 server die?
Aug 31 00:38:33 homeBox kactivitymanagerd[20173]: The X11 connection broke (error 1). Did the X11 server die?
Aug 31 00:38:33 homeBox dbus-daemon[20083]: [session uid=1002 pid=20083] Activating service name='org.kde.kglobalaccel' requested by ':1.8' (uid=1002 pid=20161 comm="/usr/bin/kwin_x11 ")
Aug 31 00:38:33 homeBox kscreen_backend_launcher[20209]: The X11 connection broke (error 1). Did the X11 server die?
Aug 31 00:38:33 homeBox systemd[20069]: app-org.kde.dolphin@9352ee02c9ba473d8d75232863751bbd.service: Main process exited, code=exited, status=1/FAILURE
Aug 31 00:38:33 homeBox systemd[20069]: app-org.kde.dolphin@9352ee02c9ba473d8d75232863751bbd.service: Failed with result 'exit-code'.
Aug 31 00:38:33 homeBox systemd[20069]: Failed to start app-org.kde.dolphin@9352ee02c9ba473d8d75232863751bbd.service.
Comment 3 David Edmundson 2020-08-30 23:41:34 UTC
and regular app loading from the menu works?

It sounds like we're autostarting before we flushed the env correctly.
Comment 4 Ahmad Samir 2020-08-31 03:29:15 UTC
Yes, I can start apps from the menu.
Comment 5 Volker Krause 2020-08-31 07:04:24 UTC
Both Andreas' and my observation were hinting at session saving breaking rather than session restore though. Things still in the session config are correctly restored here it seems.

The log during shutdown seemed to indicate X going away before processes had a chance to be cleanly terminated, both for applications (losing stuff they save themselves on exit, like kwrite's recent documents), and for kwin (which iiuc stores the list of applications to restore).
Comment 6 Ahmad Samir 2020-08-31 10:44:21 UTC
(In reply to Volker Krause from comment #5)
> Both Andreas' and my observation were hinting at session saving breaking
> rather than session restore though. Things still in the session config are
> correctly restored here it seems.
> 
> The log during shutdown seemed to indicate X going away before processes had
> a chance to be cleanly terminated, both for applications (losing stuff they
> save themselves on exit, like kwrite's recent documents), and for kwin
> (which iiuc stores the list of applications to restore).

Yes, that seems to be the case here too (bad wording / bug description on my part...).
Comment 7 David Edmundson 2020-08-31 13:07:46 UTC
Oh right.

And just to confirm this only started this month; i.e after 57438d6dfe4ecb1ae022775401f5c7bcbf2a93da (kio)

Rather than breakage going all the way back to a7d91ea3f0df1acd15ac5227f9ae371123fd91ac
Comment 8 Ahmad Samir 2020-08-31 22:32:29 UTC
Building kio from a git checkout of one commit before right before 57438d6dfe4ecb1ae022775401f5c7bcbf2a93da (since reverting it can't be done cleanly), the issue is indeed fixed.
Comment 9 Bug Janitor Service 2020-09-01 12:57:37 UTC
A possibly relevant merge request was started @ https://invent.kde.org/plasma/plasma-workspace/-/merge_requests/239
Comment 10 David Edmundson 2020-09-01 13:11:48 UTC
Git commit d24cef54d68fb29994ed610bc70867d6fc811287 by David Edmundson.
Committed on 01/09/2020 at 13:01.
Pushed by davidedmundson into branch 'master'.

[ksmserver] Use UpdateLaunchEnvJob to sync SESSION_MANAGER env

ksmserver starts in plasma-session. It currently sets the
SESSION_MANAGER env back to just kinit and plasma-session which is then
used for anything else that plasma-session starts.

This is after start-plasma has synced the environment to DBus/systemd.

By using the shared UpdateLaunchEnvJob we can sync all these places.

M  +4    -6    ksmserver/server.cpp

https://invent.kde.org/plasma/plasma-workspace/commit/d24cef54d68fb29994ed610bc70867d6fc811287
Comment 11 Ahmad Samir 2020-09-01 13:33:03 UTC
Thanks, that fixes the issue, i.e. dolphin, konsole... etc are saved/restored. However I still see this in the journal:
Sep 01 15:27:23 homeBox sddm-helper[17980]: [PAM] Closing session
Sep 01 15:27:23 homeBox sddm-helper[17980]: pam_unix(sddm:session): session closed for user ahmad
Sep 01 15:27:23 homeBox sddm-helper[17980]: [PAM] Ended.
Sep 01 15:27:23 homeBox sddm[687]: Auth: sddm-helper exited successfully
Sep 01 15:27:23 homeBox sddm[687]: Socket server stopping...
Sep 01 15:27:23 homeBox sddm[687]: Socket server stopped.
Sep 01 15:27:23 homeBox sddm[687]: Display server stopping...
Sep 01 15:27:23 homeBox plasmashell[18218]: The X11 connection broke (error 1). Did the X11 server die?
Sep 01 15:27:23 homeBox kglobalaccel5[18200]: The X11 connection broke (error 1). Did the X11 server die?
Sep 01 15:27:23 homeBox kaccess[18210]: The X11 connection broke (error 1). Did the X11 server die?
Sep 01 15:27:23 homeBox kwin_x11[18181]: The X11 connection broke (error 1). Did the X11 server die?
Sep 01 15:27:23 homeBox kactivitymanagerd[18193]: The X11 connection broke (error 1). Did the X11 server die?
Sep 01 15:27:23 homeBox kded5[18177]: Service  "org.kde.StatusNotifierHost-18218" unregistered
Sep 01 15:27:23 homeBox kded5[18177]: The X11 connection broke (error 1). Did the X11 server die?
Sep 01 15:27:23 homeBox systemd-logind[489]: Session 8 logged out. Waiting for processes to exit.
Sep 01 15:27:23 homeBox NetworkManager[676]: <info>  [1598966843.2940] device (eno1): state change: activated -> deactivating (reason 'connection-removed', sys-iface-state: 'managed')
Sep 01 15:27:23 homeBox NetworkManager[676]: <info>  [1598966843.2944] manager: NetworkManager state is now DISCONNECTING
Comment 12 Hans-Peter Jansen 2020-09-03 13:29:45 UTC
(In reply to Ahmad Samir from comment #11)
> Sep 01 15:27:23 homeBox plasmashell[18218]: The X11 connection broke (error
> 1). Did the X11 server die?

Interesting, Ahmad. This seems to affect the scripts, that should be executed on logoff, but aren't (here).
Comment 14 David Edmundson 2020-09-03 20:12:09 UTC
The plasmashell and kwin etc. not closing properly I think is completely unrelated. 

It might be an artifact of 9be7dedb87ea574916f0f8a2837eaf7b19a7a166 ?

Though it's also the case on wayland with no solved solution, and something I hope to address with https://invent.kde.org/plasma/plasma-workspace/-/merge_requests/47
Comment 15 Hans-Peter Jansen 2020-09-29 09:14:22 UTC
I see Ahmad's described behavior on some systems returning, that updated to current Tumbleweed: 

Plasma: 5.19.5
Framework: 5.74.0
Qt: 5.15.1

Hence, after we applied your fix, David: 

https://build.opensuse.org/package/view_file/openSUSE:Factory/plasma5-workspace/plasma5-workspace.changes?expand=1

Things settled again, but with move of FW from 5.73.0 to 5.74.0, the ability to restore sessions is partially lost: 

Eg. Firefox is restored, but none of the other apps: konsole, dolphin, chromium, ..

The FF special case might be related to FF using its own session management (a source of much grief for the better part of the last two decades..).

Since restoring ~/.config/plasma-org.kde.plasma.desktop-appletsrc from before these trouble started doesn't show any effect as well, the restore part seems to be the culprit here.
Comment 16 David Edmundson 2020-09-29 10:21:35 UTC
From my POV, we reverted the breaking changes in KIO for frameworks 5.74 so that no downstream would need to patch workspace to avoid breakages, so this all sounds quite backwards.

Lets first check we're talking about the same bug. If you type "env" in konsole, an app that apparently doesn't restore do you see: SESSION_MANAGER set?
Comment 17 Hans-Peter Jansen 2020-09-29 11:16:45 UTC
Hi David, thanks for caring.

(In reply to David Edmundson from comment #16)
> From my POV, we reverted the breaking changes in KIO for frameworks 5.74 so
> that no downstream would need to patch workspace to avoid breakages, so this
> all sounds quite backwards.

Hmm, workspace still have this patch applied:
https://invent.kde.org/plasma/plasma-workspace/commit/d24cef54d68fb29994ed610bc70867d6fc811287

Do you want us to revert this change?

> Lets first check we're talking about the same bug. If you type "env" in
> konsole, an app that apparently doesn't restore do you see: SESSION_MANAGER
> set?

$ env | grep SESSION
SESSION_MANAGER=local/kuno:@/tmp/.ICE-unix/2437,unix/kuno:/tmp/.ICE-unix/2437
XDG_SESSION_PATH=/org/freedesktop/DisplayManager/Session1
SHELL_SESSION_ID=527512f036d94ecbbd6123199e169fdc
DESKTOP_SESSION=/usr/share/xsessions/plasma5
XDG_SESSION_DESKTOP=KDE
XDG_SESSION_TYPE=x11
KONSOLE_DBUS_SESSION=/Sessions/1
XSESSION_IS_UP=yes
KDE_SESSION_UID=1008
XDG_SESSION_CLASS=user
KDE_SESSION_VERSION=5
XDG_SESSION_ID=2
KDE_FULL_SESSION=true
DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/1008/bus

Interestingly, on further tests, behavior changed again. Now, a konsole and a dolphin window are restored, but neither a chromium nor a spotify client window.

I noticed another strange behavior. After logging out, a lot of processes from the last user keeps running:

linus     2255  0.0  0.0  18916  4932 ?        Ss   Sep27   0:00 /usr/lib/systemd/systemd --user
linus     2256  0.0  0.0  43520   392 ?        S    Sep27   0:00 (sd-pam)
linus     2281  0.0  0.0  33624  3200 ?        Ss   Sep27   0:03 /usr/bin/dbus-daemon --session --address=systemd: --nofork --nopidfile --systemd-activation --syslog-only
linus     2304  0.0  0.0 233580   280 ?        Ssl  Sep27   0:00 /usr/libexec/gvfs/gvfsd
linus     2309  0.0  0.0 528744  1984 ?        Sl   Sep27   0:00 /usr/libexec/gvfs/gvfsd-fuse /run/user/1008/gvfs -f
linus     2452  0.0  0.0 268665624 4040 ?      SNl  Sep27   0:00 /usr/bin/baloo_file
linus     2487  0.0  0.0 155116   308 ?        Sl   Sep27   0:00 /usr/libexec/dconf-service
linus     2533  0.0  0.0  16768  1712 ?        S    Sep27   0:00 /usr/libexec/bluetooth/obexd
linus     2628  0.0  0.0  28004  1236 ?        S    Sep27   0:00 /usr/libexec/GConf/2/gconfd-2
linus     2669  0.0  0.0 304332  2072 ?        Ssl  Sep27   0:00 /usr/libexec/at-spi2/at-spi-bus-launcher
linus     2686  0.0  0.0  32128  1472 ?        S    Sep27   0:00 /usr/bin/dbus-daemon --config-file=/usr/share/defaults/at-spi2/accessibility.conf --nofork --print-address 3
linus     2849  0.0  0.0  63464  2960 ?        S    Sep27   0:02 /usr/bin/python3 /usr/bin/hp-systray -x
linus     2850  0.0  0.0  50200   788 ?        S    Sep27   0:07 /usr/bin/python3 /usr/bin/hp-systray -x
linus     2896  0.0  0.0 157216  3300 ?        Sl   Sep27   1:56 /usr/lib64/libexec/kf5/kio_http_cache_cleaner

and now, a session later, plasmashell crashed:

linus     2258  0.0  0.1  18928 11684 ?        Ss   12:59   0:00 /usr/lib/systemd/systemd --user
linus     2259  0.0  0.0  43716  4024 ?        S    12:59   0:00 (sd-pam)
linus     2284  0.1  0.1  33560  9176 ?        Ss   12:59   0:00 /usr/bin/dbus-daemon --session --address=systemd: --nofork --nopidfile --systemd-activation --syslog-only
linus     2307  0.0  0.0 233580  7776 ?        Ssl  12:59   0:00 /usr/libexec/gvfs/gvfsd
linus     2312  0.0  0.1 379216  8088 ?        Sl   12:59   0:00 /usr/libexec/gvfs/gvfsd-fuse /run/user/1008/gvfs -f
linus     2442  0.0  0.3 268665604 31608 ?     SNl  12:59   0:00 /usr/bin/baloo_file
linus     2452  2.5  7.2 4265024 588480 ?      Tl   12:59   0:18 /usr/bin/plasmashell
linus     2490  0.0  0.0 155116  5280 ?        Sl   12:59   0:00 /usr/libexec/dconf-service
linus     2536  0.0  0.0  16768  6768 ?        S    12:59   0:00 /usr/libexec/bluetooth/obexd
linus     2637  0.0  0.1  28000  9600 ?        S    12:59   0:00 /usr/libexec/GConf/2/gconfd-2
linus     2766  0.0  0.0 304332  6584 ?        Ssl  12:59   0:00 /usr/libexec/at-spi2/at-spi-bus-launcher
linus     2774  0.0  0.0  32140  7284 ?        S    12:59   0:00 /usr/bin/dbus-daemon --config-file=/usr/share/defaults/at-spi2/accessibility.conf --nofork --print-address 3
linus     2893  0.0  0.3  63452 25936 ?        S    12:59   0:00 /usr/bin/python3 /usr/bin/hp-systray -x
linus     2894  0.0  0.2  50188 18364 ?        S    12:59   0:00 /usr/bin/python3 /usr/bin/hp-systray -x
linus     2990  0.0  0.3 157324 24260 ?        Sl   13:00   0:00 /usr/lib64/libexec/kf5/kio_http_cache_cleaner
linus     3238  0.2  0.0      0     0 ?        Z    13:11   0:00 [plasmashell] <defunct>
linus     3239  0.5  0.6 282648 51480 ?        Sl   13:11   0:00 /usr/lib64/libexec/drkonqi -platform xcb -display :0 --appname plasmashell --apppath /usr/bin --signal 11 --pid 2452 --startupid 0 --restarted

IN order to avoid issues due to these artifacts, I always reboot such systems, and never re-login due to all kinds of strange behavior when doing so..
Comment 18 David Edmundson 2020-09-29 11:33:22 UTC
>Do you want us to revert this change?

Leaving it in certainly won't do any harm, but it shouldn't be needed. I played everything safe. Well we tried to, seemingly not in practice! 

>SESSION_MANAGER

This is set, so it's not the same bug. Just the same symptom.
Probably nothing to do with my cgroup usage at all? Are you in a position to compile that qputenv line out to confirm?


Can I have your ~/.config/ksmserverrc
please

>After logging out, a lot of processes from the last user keeps running.

Yeah, this is an ongoing problem. Quite bad, but somewhat unrelated I think. We have another open bug on that lets discuss that there.
Comment 19 Hans-Peter Jansen 2020-09-29 13:13:34 UTC
(In reply to David Edmundson from comment #18)
> 
> >SESSION_MANAGER
> 
> This is set, so it's not the same bug. Just the same symptom.
> Probably nothing to do with my cgroup usage at all? Are you in a position to
> compile that qputenv line out to confirm?

You lost me here - the referenced changeset doesn't contain such a line.
In general, I'm able to compile things, preferable with changes to existing builds, since I'm producing and installing RPMs for reproducibility and reversibility. 
(I'm in charge for applying your changeset to the official openSUSE plasma-workspace build).
 
> Can I have your ~/.config/ksmserverrc
> please

Will attach. Interestingly, it doesn't contain any references to the spotify and chromium apps, that were running during log off.

> >After logging out, a lot of processes from the last user keeps running.
> 
> Yeah, this is an ongoing problem. Quite bad, but somewhat unrelated I think.
> We have another open bug on that lets discuss that there.

Do you have a bug number available?
Comment 20 Hans-Peter Jansen 2020-09-29 13:15:16 UTC
Created attachment 132005 [details]
.config/ksmserverrc
Comment 21 Kishore Gopalakrishnan 2021-02-28 05:06:51 UTC
Would this bug cause session restore to fail when systemd startup is enabled, or should I report that as a separate bug?