Bug 487912 - plasma X11 session is not restored after logout/login
Summary: plasma X11 session is not restored after logout/login
Status: RESOLVED FIXED
Alias: None
Product: plasmashell
Classification: Plasma
Component: Session Management (show other bugs)
Version: 6.0.5
Platform: Arch Linux Linux
: NOR normal
Target Milestone: 1.0
Assignee: Plasma Bugs List
URL:
Keywords: regression
: 487936 488308 488442 (view as bug list)
Depends on:
Blocks:
 
Reported: 2024-06-02 07:37 UTC by Vence
Modified: 2024-06-24 15:39 UTC (History)
15 users (show)

See Also:
Latest Commit:
Version Fixed In:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Vence 2024-06-02 07:37:28 UTC
SUMMARY
With plasma-workspace upgraded from 6.0.5 to 6.0.5.1, plasma X11 session is not restored after logout/login regardless of "Desktop Session" options (last logout or manual saved) in System Setting.

STEPS TO REPRODUCE
1. Upgrade plasma -workspace to 6.0.5.1, 
2. Set "Desktop Session" option  to "last logout" or "manual saved" in System Setting
3. Logout and login

OBSERVED RESULT
New session starts as empty one. 
There are several messages "Qt: Session management error: None of the authentication protocols specified are supported" in  journalctl and no other errors.

EXPECTED RESULT
The previous session saved at last logout or manually is restored

SOFTWARE/OS VERSIONS
Linux/KDE Plasma: Arch Linux
KDE Plasma Version: 6.0.5
KDE Frameworks Version: 5.2
Qt Version: 6.7.1
Comment 1 Vence 2024-06-02 07:53:03 UTC
The bug is presumably caused by recent changes in plasma-workspace made in 6.0.5.1, namely, in ksmserver (server.cpp and server.h).

plasma-workspace 6.0.5 is free of this bug
Comment 2 Kishore Gopalakrishnan 2024-06-02 07:59:37 UTC
I also have this bug. Interestingly, applications are still opened correctly (preserving their previous state) when resuming an activity.
Comment 3 Kishore Gopalakrishnan 2024-06-02 09:20:27 UTC
(In reply to Kishore Gopalakrishnan from comment #2)
> ... Interestingly, applications are still opened correctly
> (preserving their previous state) when resuming an activity.

Scratch that. Activity supension/resumption also doesn't work for me.

When I suspend an activity, I can see using htop that those applications are still running (and thus, they still appear if I resume the same activity without rebooting). However, attempting to resume the activity after rebooting, one is indeed presented with just an empty activity.
Comment 4 Kishore Gopalakrishnan 2024-06-02 09:26:26 UTC
Installing the xorg-iceauth package does not help for me.
Comment 5 Kishore Gopalakrishnan 2024-06-02 09:35:16 UTC
After enabling 'full debug' output for ksmserver and rebooting, I get the following messages in `journalctl -b -0 --user` (I have only reproduced a segment that seems relevant)
```
Jun 02 14:59:53 kishorearchtestingVM systemd[499]: Started KDE Daemon 6.
Jun 02 14:59:53 kishorearchtestingVM ksmserver[588]: org.kde.kf6.ksmserver: "/run/user/1000/KSMserver"
Jun 02 14:59:53 kishorearchtestingVM systemd[499]: Starting KDE Configuration Module Initialization (Phase 1)...
Jun 02 14:59:53 kishorearchtestingVM ksmserver[588]: Failed to write ice auth file entry
Jun 02 14:59:53 kishorearchtestingVM ksmserver[588]: Failed to write xsmp ice auth file entry
Jun 02 14:59:53 kishorearchtestingVM ksmserver[588]: Failed to write ice auth file entry
Jun 02 14:59:53 kishorearchtestingVM ksmserver[588]: Failed to write xsmp ice auth file entry
Jun 02 14:59:53 kishorearchtestingVM ksmserver[588]: org.kde.kf6.ksmserver: KSMServer::restoreSession  "saved at previous logout"
Jun 02 14:59:53 kishorearchtestingVM systemd[499]: Started KDE Session Management Server.
Jun 02 14:59:53 kishorearchtestingVM systemd[499]: Starting KDE Plasma Workspace...
Jun 02 14:59:53 kishorearchtestingVM kcminit_startup[550]: Initializing  "/usr/lib/qt6/plugins/plasma/kcms/systemsettings/kcm_touchpad.so"
Jun 02 14:59:53 kishorearchtestingVM kcminit_startup[550]: kcm_touchpad: Using X11 backend
Jun 02 14:59:53 kishorearchtestingVM kcminit_startup[550]: Initializing  "/usr/lib/qt6/plugins/plasma/kcms/systemsettings_qwidgets/kcm_kgamma.so"
Jun 02 14:59:53 kishorearchtestingVM systemd[499]: Finished KDE Configuration Module Initialization (Phase 1).
Jun 02 14:59:53 kishorearchtestingVM kded6[590]: org.kde.libkbolt: Failed to connect to Bolt manager DBus interface:
Jun 02 14:59:53 kishorearchtestingVM kded6[590]: org.kde.bolt.kded: Couldn't connect to Bolt DBus daemon
Jun 02 14:59:53 kishorearchtestingVM systemd[499]: Started KDE Window Manager.
Jun 02 14:59:53 kishorearchtestingVM kded6[590]: org.kde.plasma.printmanager.kded: unable to register service to dbus
Jun 02 14:59:53 kishorearchtestingVM kded6[590]: QDBusObjectPath: invalid path "/modules/plasma-session-shortcuts"
Jun 02 14:59:53 kishorearchtestingVM kded6[590]: kf.dbusaddons: The kded module name "plasma-session-shortcuts" is invalid!
Jun 02 14:59:53 kishorearchtestingVM systemd[499]: Starting KActivityManager Activity manager Service...
Jun 02 14:59:53 kishorearchtestingVM kded6[590]: QDBusObjectPath: invalid path "/modules/kded_plasma-welcome"
Jun 02 14:59:53 kishorearchtestingVM kded6[590]: kf.dbusaddons: The kded module name "kded_plasma-welcome" is invalid!
Jun 02 14:59:53 kishorearchtestingVM kded6[590]: kcm_touchpad: Using X11 backend
Jun 02 14:59:53 kishorearchtestingVM ksmserver[588]: org.kde.kf6.ksmserver: KSMConnection::count 1
Jun 02 14:59:53 kishorearchtestingVM ksmserver[588]: org.kde.kf6.ksmserver: ICE Connection rejected!
Jun 02 14:59:53 kishorearchtestingVM plasmashell[607]: Qt: Session management error: None of the authentication protocols specified are supported
```
Comment 6 Kishore Gopalakrishnan 2024-06-02 09:57:12 UTC
In ksmserver/server.cpp, I see (around line 365)
```
            if (IceWriteAuthFileEntry(fp, file_entry) != 0) {
                qWarning("Failed to write ice auth file entry");
            }
```
but the documentation for IceWriteAuthFileEntry ( https://www.x.org/releases/X11R7.7/doc/libICE/ICElib.html#IceWriteAuthFileEntry ) says "The function returns a nonzero status if the operation was successful. "

I suppose this means the 'Failed to write ice auth file entry' messages in my logs in comment 5 may be misleading.
Comment 7 Kishore Gopalakrishnan 2024-06-02 11:48:25 UTC
I can at least confirm that my iceauth file (/run/user/1000/iceauth_XXXXXX , where XXXXXX is some apparently random string) is empty, so perhaps ksmserver is indeed failing to write the 'magic cookie' (whatever that is) to that file.
Comment 8 Jesus 2024-06-02 19:36:43 UTC
Confirmed, this happens with the latest version of plasma-workspace 6.0.5.1, if I install the previous 6.0.5 the session restoration works again
Comment 9 Eduardo 2024-06-03 11:50:20 UTC
I can confirm this, luckily I could revert to 6.0.5, heavily rely on session restore functionality.
I even restored home FS to a snapshot before I logged in with broken session restore, to be sure.
Comment 10 Eduardo 2024-06-03 11:55:03 UTC
(In reply to Kishore Gopalakrishnan from comment #7)
> I can at least confirm that my iceauth file (/run/user/1000/iceauth_XXXXXX ,
> where XXXXXX is some apparently random string) is empty, so perhaps
> ksmserver is indeed failing to write the 'magic cookie' (whatever that is)
> to that file.

I don't even have this file on my system with 6.0.5 where everything works just fine. So I would not be so sure that the issue is there.
Comment 11 i.Dark_Templar 2024-06-03 15:16:48 UTC
(In reply to Eduardo from comment #10)
> (In reply to Kishore Gopalakrishnan from comment #7)
> > I can at least confirm that my iceauth file (/run/user/1000/iceauth_XXXXXX ,
> > where XXXXXX is some apparently random string) is empty, so perhaps
> > ksmserver is indeed failing to write the 'magic cookie' (whatever that is)
> > to that file.
> 
> I don't even have this file on my system with 6.0.5 where everything works
> just fine. So I would not be so sure that the issue is there.

That is the issue. With new release this file is created, written, but not flushed or closed, so it stays empty. And new env variable ICEAUTHORITY pointing to this file is set up. Flushing or closing file fixed issue for me with plasma workspace 5.27.11.1 as in https://bugs.kde.org/show_bug.cgi?id=487936#c3.
Comment 12 Vence 2024-06-03 15:38:20 UTC
(In reply to i.Dark_Templar from comment #11)
> 
> That is the issue. With new release this file is created, written, but not
> flushed or closed, so it stays empty. And new env variable ICEAUTHORITY
> pointing to this file is set up. Flushing or closing file fixed issue for me
> with plasma workspace 5.27.11.1 as in
> https://bugs.kde.org/show_bug.cgi?id=487936#c3.

Could you explain how can one close or flush this file?
Comment 13 Kishore Gopalakrishnan 2024-06-03 16:04:08 UTC
*** Bug 487936 has been marked as a duplicate of this bug. ***
Comment 14 Eduardo 2024-06-03 16:04:54 UTC
(In reply to i.Dark_Templar from comment #11)
> That is the issue. With new release this file is created, written, but not
> flushed or closed, so it stays empty. And new env variable ICEAUTHORITY
> pointing to this file is set up. Flushing or closing file fixed issue for me
> with plasma workspace 5.27.11.1 as in
> https://bugs.kde.org/show_bug.cgi?id=487936#c3.

Good catch!
Comment 15 Vence 2024-06-04 07:27:03 UTC
After plasma workspace 6.0.5.1 is rebuilt with the following patch applied, everything seems to be quite right: 
-- $ICEAUTHORITY=/run/user/1000/iceauth_XXXXX
-- file iceauth_XXXXX does exist and is not empty
-- plasma X11 session is saved and restored correctly.

--- a/ksmserver/server.cpp<---->2024-05-31 15:48:02.000000000 +0300
+++ b/ksmserver/server.cpp<---->2024-06-04 08:47:52.966458262 +0300
@@ -397,6 +397,7 @@
         IceSetPaAuthData(2, &(*authDataEntries)[i]);
     }
.
+    (void)fclose(fp);
     return (1);
 }
Comment 16 Bug Janitor Service 2024-06-04 07:46:42 UTC
A possibly relevant merge request was started @ https://invent.kde.org/plasma/plasma-workspace/-/merge_requests/4405
Comment 17 David Edmundson 2024-06-04 08:08:11 UTC
Thanks for following up so quickly.
Comment 18 Vence 2024-06-04 08:14:34 UTC
In addition to Comment 15:
There are still the following messages in journalctl:

ksmserver[983]: Failed to write ice auth file entry
ksmserver[983]: Failed to write xsmp ice auth file entry
ksmserver[983]: Failed to write ice auth file entry
ksmserver[983]: Failed to write xsmp ice auth file entry

However, iceauth command shows that all the entries are is written correctly into the /run/user/1000/iceauth_XXXXX file.

Kishore Gopalakrishnan in Comment #6 notices that the function IceWriteAuthFileEntry returns a nonzero status if the operation was successful. 
So the condition "if (IceWriteAuthFileEntry(fp, file_entry) != 0)" in ksmserver/server.cpp (lines 367,391) should be "if (IceWriteAuthFileEntry(fp, file_entry) = 0)"
Comment 19 Fushan Wen 2024-06-04 11:58:13 UTC
Git commit 0dcf34458d99b07a3d9054ae0c86c656e0dfa7aa by Fushan Wen, on behalf of Tomáš Trnka.
Committed on 04/06/2024 at 11:39.
Pushed by fusionfuture into branch 'master'.

Fix writing ICEAuthority file

Commit 9398f6cf8933055b31506ba155aef2fc2b3561d7 "Remove iceauth
dependency" introduced two bugs:

1) "fp" is never closed, so the generated auth data stays buffered in
   memory for some indeterminate time and the file stays empty on disk.
   This completely breaks authentication and thus also session restore.

2) Checking the return value of IceWriteAuthFileEntry() is inverted (the
   function returns non-zero on success), so warnings are printed iff
   everything goes well.

M  +7    -2    ksmserver/server.cpp

https://invent.kde.org/plasma/plasma-workspace/-/commit/0dcf34458d99b07a3d9054ae0c86c656e0dfa7aa
Comment 20 Fushan Wen 2024-06-04 12:50:09 UTC
Git commit 0857d18dfc3fc870a7f768731fdf46dc3abc5f8f by Fushan Wen.
Committed on 04/06/2024 at 12:17.
Pushed by fusionfuture into branch 'Plasma/6.1'.

Fix writing ICEAuthority file

Commit 9398f6cf8933055b31506ba155aef2fc2b3561d7 "Remove iceauth
dependency" introduced two bugs:

1) "fp" is never closed, so the generated auth data stays buffered in
   memory for some indeterminate time and the file stays empty on disk.
   This completely breaks authentication and thus also session restore.

2) Checking the return value of IceWriteAuthFileEntry() is inverted (the
   function returns non-zero on success), so warnings are printed iff
   everything goes well.


(cherry picked from commit 0dcf34458d99b07a3d9054ae0c86c656e0dfa7aa)

Co-authored-by: Tomáš Trnka <tomastrnka@gmx.com>

M  +7    -2    ksmserver/server.cpp

https://invent.kde.org/plasma/plasma-workspace/-/commit/0857d18dfc3fc870a7f768731fdf46dc3abc5f8f
Comment 21 Fushan Wen 2024-06-04 12:50:20 UTC
Git commit 1181acfe30557d6646511df8d98d82589878a570 by Fushan Wen.
Committed on 04/06/2024 at 12:18.
Pushed by fusionfuture into branch 'Plasma/5.27'.

Fix writing ICEAuthority file

Commit 9398f6cf8933055b31506ba155aef2fc2b3561d7 "Remove iceauth
dependency" introduced two bugs:

1) "fp" is never closed, so the generated auth data stays buffered in
   memory for some indeterminate time and the file stays empty on disk.
   This completely breaks authentication and thus also session restore.

2) Checking the return value of IceWriteAuthFileEntry() is inverted (the
   function returns non-zero on success), so warnings are printed iff
   everything goes well.


(cherry picked from commit 0dcf34458d99b07a3d9054ae0c86c656e0dfa7aa)

Co-authored-by: Tomáš Trnka <tomastrnka@gmx.com>

M  +7    -2    ksmserver/server.cpp

https://invent.kde.org/plasma/plasma-workspace/-/commit/1181acfe30557d6646511df8d98d82589878a570
Comment 22 S. Umar 2024-06-04 14:35:09 UTC
I have also noticed that gtk apps that are on the desktop (I use gkrellm) multiply after logout/login or reboot. I have gkrellm on the desktop and I noticed many copies of it running. I killed them all started one and tested again and they keep multiplying. I will test to see if this patch fixes that too.
Comment 23 S. Umar 2024-06-04 14:46:21 UTC
No it did not. I will open a new case
Comment 24 Antonio Rojas 2024-06-06 10:48:32 UTC
This needs to be backported to 6.0 too (and a 6.0.5.2 tarball released). Currently there is a security advisory asking users to upgrade to a broken version.
Comment 25 S. Umar 2024-06-06 12:48:25 UTC
Fedora 40 included these patches in a new version. However, it seems to break the logout from KDE plasma. When I select logout (on multiple computers) I get a black screen with the mouse cursor showing only.
Comment 26 David Edmundson 2024-06-09 08:40:51 UTC
Git commit 918cb38c3522ffcc241ac6a22b6741e41cdd3c30 by David Edmundson, on behalf of David Edmundson.
Committed on 09/06/2024 at 08:25.
Pushed by davidedmundson into branch 'Plasma/6.0'.

Fix writing ICEAuthority file

Commit 9398f6cf8933055b31506ba155aef2fc2b3561d7 "Remove iceauth
dependency" introduced two bugs:

1) "fp" is never closed, so the generated auth data stays buffered in
   memory for some indeterminate time and the file stays empty on disk.
   This completely breaks authentication and thus also session restore.

2) Checking the return value of IceWriteAuthFileEntry() is inverted (the
   function returns non-zero on success), so warnings are printed iff
   everything goes well.


(cherry picked from commit 0dcf34458d99b07a3d9054ae0c86c656e0dfa7aa)

Co-authored-by: Tomáš Trnka <tomastrnka@gmx.com>

M  +7    -2    ksmserver/server.cpp

https://invent.kde.org/plasma/plasma-workspace/-/commit/918cb38c3522ffcc241ac6a22b6741e41cdd3c30
Comment 27 Vence 2024-06-10 21:17:11 UTC
*** Bug 488308 has been marked as a duplicate of this bug. ***
Comment 28 krovikan 2024-06-13 16:18:55 UTC
*** Bug 488442 has been marked as a duplicate of this bug. ***