Bug 203715 - kio_imap4 eats randomly too much cpu
Summary: kio_imap4 eats randomly too much cpu
Status: RESOLVED FIXED
Alias: None
Product: kio
Classification: Frameworks and Libraries
Component: imap (show other bugs)
Version: unspecified
Platform: Fedora RPMs Unspecified
: NOR normal
Target Milestone: ---
Assignee: kdepim bugs
URL:
Keywords:
: 187077 (view as bug list)
Depends on:
Blocks:
 
Reported: 2009-08-13 14:53 UTC by LukasT
Modified: 2010-03-02 21:31 UTC (History)
5 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 LukasT 2009-08-13 14:53:06 UTC
Version:            (using KDE 4.3.0)
Installed from:    Fedora RPMs

Sometimes kio_imap4 pop-ups in top statistics and eats both cores on my laptop with dual core.

How to reproduce:
appears randomly, but when you notice rapid slowdown (I use System monitor plasmoid), run konsole, top and check top two processes 
which were kio_imap4.

This bug appeared 3-4 times so far.
Comment 1 LukasT 2009-08-21 15:36:25 UTC
I did observation and this bug appear almost everytime I close the Kontact with x button in the row and 
it is not minimized (as it should be) into systray but it close itself and then the kio_imap4 eats both cores.
Comment 2 Tim Middleton 2009-11-06 15:24:51 UTC
Happens to me when I resume my laptop from 'sleep'. But only happens maybe 20% of the time, so I haven't been able to figure out any sort of pattern. I theorize that kio_imap4 may be upset about sudden network disappearance during one of it's operations, but this is a wild guess and may not apply to the situation described by others.
Comment 3 Tomas Trnka 2010-01-07 00:23:17 UTC
I had recently been hitting this bug few times a day and today I finally found time to investigate it. 

kio_imap4 falls into an infinite loop if any connection error occurs during authentication (e.g. connection is suddenly lost). The backtrace looks like this:

#0  0x00007f86a8bdd91e in IMAP4Protocol::parseReadLine (this=0xdea4e0, buffer=<value optimized out>, relay=0)
    at /usr/src/debug/kdepimlibs-4.3.4/kioslave/imap4/imap4.cpp:766
#1  0x00007f86a8c08ef2 in imapParser::parseLoop (this=0xdea510)
    at /usr/src/debug/kdepimlibs-4.3.4/kioslave/imap4/imapparser.cpp:1725
#2  0x00007f86a8c0b863 in imapParser::clientAuthenticate (this=0xdea510, slave=<value optimized out>,
    ai=<value optimized out>, aFQDN=<value optimized out>, aAuth=<value optimized out>, isSSL=<value optimized out>,
    resultInfo=<value optimized out>) at /usr/src/debug/kdepimlibs-4.3.4/kioslave/imap4/imapparser.cpp:268
#3  0x00007f86a8be15fd in IMAP4Protocol::makeLogin (this=0xdea4e0)
    at /usr/src/debug/kdepimlibs-4.3.4/kioslave/imap4/imap4.cpp:2133

When IMAP4Protocol::parseReadLine detects it's not connected, it returns false. This causes imapParser::parseLoop to return -1. However, imapParser::clientAuthenticate doesn't check for this and (using a while(true) loop) keeps retrying indefinitely.
This should be trivial to fix (properly check the return value of imapParser::parseLoop and bail out if -1). However, I do not currently have time to test the fix properly, so it will have to wait for a week or so...
Comment 4 Allen Winter 2010-01-07 00:49:13 UTC
Tomas, thanks!
Once we have a working patch I will ask the distros to push it out to their users.

Here's a possible patch for people to try
Index: /data/kde/trunk/KDE/kdepimlibs/kioslave/imap4/imapparser.cpp
===================================================================
--- /data/kde/trunk/KDE/kdepimlibs/kioslave/imap4/imapparser.cpp        (revision 1070797)
+++ /data/kde/trunk/KDE/kdepimlibs/kioslave/imap4/imapparser.cpp        (working copy)
@@ -265,9 +265,11 @@ imapParser::clientAuthenticate ( KIO::Sl
   while ( true )
   {
     //read the next line
-    while (parseLoop() == 0) {
+    int parseStat;
+    while ( ( parseStat = parseLoop() ) == 0) {
       ;
     }
+    if ( parseStat < 0 ) break;
     if ( cmd->isComplete() ) break;

     if (!continuation.isEmpty())
Comment 5 Allen Winter 2010-01-07 21:49:20 UTC
Here is another, possibly better (untested) patch:

Index: imapparser.cpp
===================================================================
--- imapparser.cpp      (revision 1071187)
+++ imapparser.cpp      (working copy)
@@ -262,13 +262,12 @@ imapParser::clientAuthenticate ( KIO::Sl
   }
   cmd = sendCommand (CommandPtr(new imapCommand ("AUTHENTICATE", firstCommand.toLatin1())));

-  while ( true )
-  {
+  int pl = 0;
+  while ( pl != -1 && !cmd->isComplete () ) {
     //read the next line
-    while (parseLoop() == 0) {
+    while ( ( pl = parseLoop() ) == 0) {
       ;
     }
-    if ( cmd->isComplete() ) break;

     if (!continuation.isEmpty())
     {
Comment 6 Tomas Trnka 2010-01-13 16:04:25 UTC
SVN commit 1074158 by ttrnka:

Properly check errors during authentication to avoid falling into an infinite loop.

BUG:203715



 M  +3 -4      imapparser.cpp  


WebSVN link: http://websvn.kde.org/?view=rev&revision=1074158
Comment 7 Allen Winter 2010-01-13 16:59:20 UTC
SVN commit 1074179 by winterz:

backport SVN commit r1074158 by ttrnka:

Properly check errors during authentication to avoid falling into an infinite loop.

CCBUG:203715


 M  +3 -4      imapparser.cpp  


WebSVN link: http://websvn.kde.org/?view=rev&revision=1074179
Comment 8 Tomas Trnka 2010-03-02 21:31:00 UTC
*** Bug 187077 has been marked as a duplicate of this bug. ***