[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-core-devel
Subject:    Re: Unsolvable problem with pop3 kioslave.
From:       Dawit Alemayehu <adawit () earthlink ! net>
Date:       1999-12-23 17:47:07
[Download RAW message or body]

On Thu, 23 Dec 1999, Don Sanders wrote:
> I don't know if anyone can help me with this but here goes...
> 
> I have a problem with pop3 commands hanging the slave. This is because
> sometimes after the pop3 slave issues a command to the server, something goes
> wrong the slave never receives the response it wants and loops forever (or at
> least until I kill the process).
>
> This happens in all kinds of methods like listDir, get, del, but only sometimes.
> 
> The problematic code is pop3.cc in kdebase/kioslave/pop3, in particular
> sometimes the ::select function always returns 0, and the while loop doesn't
> terminate.
> 
> Does anyone have any ideas what to do about this? I'm afraid I'm a bit out of
> me league here. I don't know why this is happening, I don't know if it happens
> to anyone else and I don't know the appropriate remedy.

First let me start by saying I am no expert at this.  Having said that it looks
like the ::select function is always timing out to cause the blocking. 
::select returns a 0 if it times out before anything intersting happens.  This
is probably becuase the server does not respond at all to the request/command
that was sent to it.  I believe the author likely did not take that into account
since the comment right before the loop states "// And keep waiting if it timed out".
IMHO, this is wrong becuase it does not deal with the condition where the
server does not respond for whatever the reasons.  This is probably why you are
only seeing it sometimes.

Anyway, can you test out the patch below to see if it fixes this problem and
does not cause another(it should not but who knows) ?  It sets a
MAX_TIMESOUTS_ALLOWED value and checks against it in the loop to
make sure that it does not loop forever ...

[snipped code]

Regards,
Dawit A.
["pop3.diff" (text/english)]

Index: pop3.cc
===================================================================
RCS file: /home/kde/kdebase/kioslave/pop3/pop3.cc,v
retrieving revision 1.33
diff -u -r1.33 pop3.cc
--- pop3.cc	1999/10/24 19:09:24	1.33
+++ pop3.cc	1999/12/23 18:35:46
@@ -26,6 +26,12 @@
 
 #include "pop3.h"
 
+// This value is used to determine how long we should loop
+// and wait for a response from the server before giving up.
+// The value 9 corresponds to 45 secs based on the looping
+// code in the getResponse() member functions. (Dawit A.)
+#define MAX_TIMEOUTS_ALLOWED 9
+
 bool open_PassDlg( const QString& _head, QString& _user, QString& _pass );
 
 int main(int , char **)
@@ -73,8 +79,14 @@
   FD_SET(m_iSock, &FDs);
 
   // And keep waiting if it timed out
+  // No!! we need to give up after a specific
+  // amount of time and error out.  Otherwise
+  // it is possible that we wait forever if the
+  // server for whatever reason does not respond!!!
   unsigned int wait_time=1;
-  while (::select(m_iSock+1, &FDs, 0, 0, &m_tTimeout) ==0) {
+  while (::select(m_iSock+1, &FDs, 0, 0, &m_tTimeout) ==0 &&
+         wait_time <= MAX_TIMEOUTS_ALLOWED )
+  {
     // Yes, it's true, Linux sucks.
     wait_time++;
     m_tTimeout.tv_sec=wait_time;


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic