Bug 102046

Summary: login hangs with some settings
Product: [Plasma] kwin Reporter: Andrew Schulman <andrex>
Component: generalAssignee: KWin default assignee <kwin-bugs-null>
Status: RESOLVED FIXED    
Severity: normal CC: hubn3rd, l4u65v002
Priority: NOR    
Version: unspecified   
Target Milestone: ---   
Platform: Debian testing   
OS: Linux   
Latest Commit: Version Fixed In:
Sentry Crash Report:
Attachments: Traceback from offending klauncher process
ps auxwww | grep klauncher

Description Andrew Schulman 2005-03-21 04:51:27 UTC
Version:            (using KDE KDE 3.4.0)
Installed from:    Debian testing/unstable Packages
OS:                Linux

I start with a fresh installation of KDE 3.4, using the Debian experimental packages.  I remove ~/.kde, log in for the first time, and start to configure my desktop.  Periodically I log out and log back in.  At some point, I can no longer log back in again because the login hangs at the "Restoring the panel" stage.  If I kill klauncher, I get an error dialog but the login completes and I can use my desktop.

There seem to be many combinations of settings and startup applications that cause klauncher to hang.  I haven't identified them all, but I have definitely isolated two:

(1) Turning off the annoying login music.  In the Control Center this is
Sound -> System notifications -> KDE System Notifications -> KDE is
starting up.  In .kde/share/config/knotify.eventsrc, turning off that sound
changes "1" to "0" in the section

[startkde]
commandline=
logfile=
presentation=1
soundfile=KDE_Startup_1.ogg

And indeed, I can now reliably turn the hang on and off (at least, with
respect to this setting) just by changing that presentation setting from 1
to 0 and back again.  When I set presentation=0, login hangs.  When
presentation=1, it doesn't.

(2) Configuring a kwallet.  As soon as I do this, login will hang every time.  Even
removing .kde/share/config/kwalletrc and .kde/share/apps/kwallet doesn't
solve the problem; I have to delete ~/.kde and restore it from backup.

At least now I know how to finish logging in, by killing klauncher.  But I shouldn't have to do that.

Any help appreciated.
Andrew.
Comment 1 Andrew Schulman 2005-03-21 11:30:33 UTC
A clarification: login hangs during the "Restoring session" stage.  In .kde/share/config/ksmserverrc, I have

program1=kwin
program2=konsole
program3=kgpg
program4=kmail
program5=kwalletmanager
program6=knode
program7=kalarm
program8=kopete

and only the first 3 of these start before the login hangs.
Comment 2 Lubos Lunak 2005-04-22 18:28:59 UTC
Please attach gdb to the hung process and provide the backtrace here.
Comment 3 Lubos Lunak 2005-06-06 16:45:35 UTC
Waiting for a response.
Comment 4 l4u65v002@sneakemail.com 2005-08-07 20:46:58 UTC
I'm having the same problem; at least, I get hangs at login using KDE 3.4.1 with gentoo, and killing klauncher allows the login to proceed.  (Further details in the gentoo bug I filed: <http://bugs.gentoo.org/show_bug.cgi?id=99866>.)

Unfortunately, even though I have debug symbols in my KDE build, if I try to attach gdb to the hung klauncher process (I do 'ps uxaww | grep klauncher' to get the pid, 'gdb /usr/kde/3.4/bin/klauncher', then in gdb 'attach nnnn' where nnnn is the pid), I just get this:

Attaching to program: /usr/kde/3.4/bin/klauncher, process nnnn
Failed to read a valid object file image from memory.
0xXXXXXXXX in ?? ()

where 0xXXXXXXX is some random hex value.  The resulting stack trace (from 'where') is garbage (just hex values, some of which are obviously wrong, like 0x0a).

Please advise on what I can do to help track this down.

Comment 5 Thiago Macieira 2005-09-02 09:44:24 UTC
*** Bug 111921 has been marked as a duplicate of this bug. ***
Comment 6 Christian Loose 2005-09-02 10:03:02 UTC
l4u65v002@sneakemail.com seems to be willing to provide more information...
Comment 7 Dean Montogmery 2005-09-14 09:20:46 UTC
I have the same problem using kubuntu.  I've noticed kde will lock up if the session contains gkrellm or kontact or kopete.  I have to manually remove those applications from ~/.kde/share/config/ksmserverrc or just `rm ksmserverrc`
Comment 8 l4u65v002@sneakemail.com 2005-09-17 22:44:32 UTC
Yes, I'll be glad to provide more information if someone will tell me what information is needed.
Comment 9 Lubos Lunak 2005-10-03 15:40:58 UTC
Don't use "gdb <binary> ; attach <pid>" but only "gdb; attach <pid>", i.e. leave out the klauncher binary, and try again.
Comment 10 l4u65v002@sneakemail.com 2005-10-04 04:52:55 UTC
Created attachment 12836 [details]
Traceback from offending klauncher process

Yes, that did the trick.  Traceback from klauncher attached; if I kill this
process, kde proceeds, but only the konsole shows up (not the xemacs, kpp or
xosview that ought to show up).
Comment 11 Dean Montogmery 2005-10-05 04:00:25 UTC
Created attachment 12855 [details]
ps auxwww | grep klauncher

When klauncher stops kde at the "Restoring Session" splash, I noticed through
ps auxwww | grep klauncher that kio_file and kio_media are in the list.  So I
disabled the sound system in kde and removed all "system notification" sounds
from the Control Center and removed kmix.  Now the system starts up just fine,
and does not hang, except now there is no sound.
Comment 12 Dean Montogmery 2005-10-05 04:22:41 UTC
I narrowed it down some more.  I re-enabled the sound system and kmix then re-enabled all "system notification" sounds except for the "KDE Window Manager" sounds.  I suspect kde is restoring windows during the "restoring session" splash screen and the sound system is not able to properly generate the sounds for these windows.  I'm happy now that I don't have to
 ctrl+alt+f1,
 login,
 killall klaucher
in order to get kde to work.
Comment 13 Andrew Schulman 2005-10-05 12:28:46 UTC
> I narrowed it down some more.  I re-enabled the sound system and
> kmix then re-enabled all "system notification" sounds except for the
> "KDE Window Manager" sounds.  I suspect kde is restoring windows during
> the "restoring session" splash screen and the sound system is not able
> to properly generate the sounds for these windows.  


Confirmed here:  disabling KDE Window Manager sounds allows login to 
proceed normally.  Thanks for tracking that down.

> I'm happy now that I 
> don't have to ctrl+alt+f1,
>  login,
>  killall klaucher
> in order to get kde to work.


Got that right.
Comment 14 Lubos Lunak 2005-10-07 13:07:02 UTC
SVN commit 468171 by lunakl:

Fix a lockup between kwin and klauncher. Quite strange not many people
have noticed. KWin grabs X server, and may have knotify events during
the grab. Which may result in knotify daemon starting, and klauncher
may do X operations during that. So it hangs up waiting for X and
KWin keeps X grabbed waiting for knotifyclient call to return.
BUG: 102046



 M  +28 -2     notifications.cpp  
 M  +9 -0      notifications.h  
 M  +11 -0     utils.cpp  
 M  +1 -0      utils.h  


--- branches/KDE/3.5/kdebase/kwin/notifications.cpp #468170:468171
@@ -92,9 +92,11 @@
     return event;
     }
 
+static bool forgetIt = FALSE;
+QValueList< Notify::EventData > Notify::pending_events;
+
 bool Notify::raise( Event e, const QString& message, Client* c )
     {
-    static bool forgetIt = FALSE;
     if ( forgetIt )
         return false; // no connection was possible, don't try each time
 
@@ -102,11 +104,35 @@
     if ( !event )
         return false;
 
+// There may be a deadlock if KNotify event is sent while KWin has X grabbed.
+// If KNotify is not running, KLauncher may do X requests (startup notification, whatever)
+// that will block it. And KNotifyClient waits for the launch to succeed, which means
+// KLauncher waits for X and KWin waits for KLauncher. So postpone events in such case.
+    if( grabbedXServer())
+        {
+        EventData data;
+        data.event = event;
+        data.message = message;
+        data.window = c ? c->window() : 0;
+        pending_events.append( data );
+        return true;
+        }
+
     forgetIt= !KNotifyClient::event( c ? c->window() : 0, event, message );
-
     return !forgetIt;
     }
 
+void Notify::sendPendingEvents()
+    {
+    while( !pending_events.isEmpty())
+        {
+        EventData data = pending_events.first();
+        pending_events.pop_front();
+        if( !forgetIt )
+            forgetIt= !KNotifyClient::event( data.window, data.event, data.message );
+        }
+    }
+
 bool Notify::makeDemandAttention( Event e )
     {
     QString event = eventToName( e );
--- branches/KDE/3.5/kdebase/kwin/notifications.h #468170:468171
@@ -14,6 +14,7 @@
 
 #include <stdlib.h>
 #include <qstring.h>
+#include <qvaluelist.h>
 
 namespace KWinInternal
 {
@@ -51,8 +52,16 @@
 
         static bool raise( Event, const QString& message = QString::null, Client* c = NULL );
         static bool makeDemandAttention( Event );
+        static void sendPendingEvents();
     private:
         static QString eventToName( Event );
+        struct EventData
+            {
+            QString event;
+            QString message;
+            long window;
+            };
+        static QValueList< EventData > pending_events;
     };
 
 } // namespace
--- branches/KDE/3.5/kdebase/kwin/utils.cpp #468170:468171
@@ -30,6 +30,7 @@
 #include <X11/Xatom.h>
 
 #include "atoms.h"
+#include "notifications.h"
 
 extern Time qt_x_time;
 
@@ -282,8 +283,18 @@
     {
     assert( server_grab_count > 0 );
     if( --server_grab_count == 0 )
+        {
         XUngrabServer( qt_xdisplay());
+        XFlush( qt_xdisplay());
+        Notify::sendPendingEvents();
+        }
     }
+    
+bool grabbedXServer()
+    {
+    return server_grab_count > 0;
+    }
+
 #endif
 
 bool isLocalMachine( const QCString& host )
--- branches/KDE/3.5/kdebase/kwin/utils.h #468170:468171
@@ -188,6 +188,7 @@
 void updateXTime();
 void grabXServer();
 void ungrabXServer();
+bool grabbedXServer();
 
 // the docs say it's UrgencyHint, but it's often #defined as XUrgencyHint
 #ifndef UrgencyHint
Comment 15 Andrew Schulman 2005-10-07 13:14:00 UTC
> Fix a lockup between kwin and klauncher. Quite strange not many people
> have noticed. KWin grabs X server, and may have knotify events during
> the grab. Which may result in knotify daemon starting, and klauncher
> may do X operations during that. So it hangs up waiting for X and
> KWin keeps X grabbed waiting for knotifyclient call to return.


Thank you!  I'll look forward to the fix.
Comment 16 Lubos Lunak 2005-10-27 13:28:11 UTC
*** Bug 104408 has been marked as a duplicate of this bug. ***