Krishna PMV | 6 Jul 2012 11:39
Picon

[RCU] How to configure timeout on external http calls

hey,
We are facing a problem with tiny_mc  plugin where users  seems to be inserting media/images by placing external urls which doesn't seem to respond for ever. As a result, all our httpd processes are waiting on those external network calls and affecting rest of the users. We have temporarily disabled tiny_mc and looking for ways to configure timeout either globally in roundcube or specifically for this plugin for ALL external http calls that roundcube makes. Any help is highly appreciated. 

Thanks!

fyi - we are running :
roundcube-0.6-81336 
php-5.2.5-1
httpd-2.2.3-45
_______________________________________________
Roundcube Users mailing list
users@...
http://lists.roundcube.net/mailman/listinfo/users
Krishna PMV | 9 Jul 2012 07:17
Picon

Re: [RCU] How to configure timeout on external http calls

On Fri, Jul 6, 2012 at 3:09 PM, Krishna PMV <krishna.pmv-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:

hey,
We are facing a problem with tiny_mc  plugin where users  seems to be inserting media/images by placing external urls which doesn't seem to respond for ever. As a result, all our httpd processes are waiting on those external network calls and affecting rest of the users. We have temporarily disabled tiny_mc and looking for ways to configure timeout either globally in roundcube or specifically for this plugin for ALL external http calls that roundcube makes.
_______________________________________________
Roundcube Users mailing list
users@...
http://lists.roundcube.net/mailman/listinfo/users
A.L.E.C | 9 Jul 2012 10:03
Picon
Gravatar

Re: [RCU] How to configure timeout on external http calls

On 07/09/2012 07:17 AM, Krishna PMV wrote:
> Ok, it turns out to be a bug in roundcube here:
> https://svn.roundcube.net/trunk/roundcubemail/program/steps/utils/modcss.inc
> 
> Its neatly explained here:
> http://in2.php.net/manual/en/function.stream-set-timeout.php#71274

I think there was a similiar issue in IMAP connections handling. Please,
try with this patch.

--- program/steps/utils/modcss.inc
+++ program/steps/utils/modcss.inc
 <at>  <at>  -59,7 +59,7  <at>  <at>  fwrite($fp, $out);
 // read response
 $header = true;
 $headers = array();
-while (!feof($fp)) {
+while (!socket_eof($fp)) {
     $line = trim(fgets($fp, 4048));

     if ($header) {
 <at>  <at>  -96,3 +96,19  <at>  <at>  echo $error;
 exit;

+function socket_eof($fp)
+{
+    if (!is_resource($fp)) {
+        return true;
+    }
+
+    // If a connection opened by fsockopen() wasn't closed
+    // by the server, feof() will hang.
+    $start = microtime(true);
+
+    if (feof($fp) || microtime(true) - $start > 30) {
+        return true;
+    }
+
+    return false;
+}

--

-- 
Aleksander 'A.L.E.C' Machniak
LAN Management System Developer [http://lms.org.pl]
Roundcube Webmail Developer  [http://roundcube.net]
---------------------------------------------------
PGP: 19359DC1  <at>  <at>  GG: 2275252  <at>  <at>  WWW: http://alec.pl
_______________________________________________
Roundcube Users mailing list
users@...
http://lists.roundcube.net/mailman/listinfo/users

A.L.E.C | 9 Jul 2012 10:45
Picon
Gravatar

Re: [RCU] How to configure timeout on external http calls

On 07/09/2012 10:03 AM, A.L.E.C wrote:
> I think there was a similiar issue in IMAP connections handling. Please,
> try with this patch.

Please, also give a try to the attached patch. It simplifies the code
significantly and moves timeout handling to the PHP internals.

--

-- 
Aleksander 'A.L.E.C' Machniak
LAN Management System Developer [http://lms.org.pl]
Roundcube Webmail Developer  [http://roundcube.net]
---------------------------------------------------
PGP: 19359DC1  <at>  <at>  GG: 2275252  <at>  <at>  WWW: http://alec.pl
Attachment (modcss_2.patch): text/x-diff, 2609 bytes
_______________________________________________
Roundcube Users mailing list
users@...
http://lists.roundcube.net/mailman/listinfo/users
Krishna PMV | 9 Jul 2012 12:30
Picon

Re: [RCU] How to configure timeout on external http calls

hey Alec,

On Mon, Jul 9, 2012 at 1:33 PM, A.L.E.C <alec-9L+TqMifR6s@public.gmane.org> wrote:
On 07/09/2012 07:17 AM, Krishna PMV wrote:
> Ok, it turns out to be a bug in roundcube here:
> https://svn.roundcube.net/trunk/roundcubemail/program/steps/utils/modcss.inc
>
> Its neatly explained here:
> http://in2.php.net/manual/en/function.stream-set-timeout.php#71274

I think there was a similiar issue in IMAP connections handling.

I see in the version we are using ( 0.6-81336) , its handled well.

 
Please, try with this patch.

We've applied the following patch for this already. Hopefully it should work. Thanks a ton for your patch anyways.

--- modcss.inc.      2012-07-09 03:56:02.000000000 -0400
+++ modcss.inc  2012-07-09 04:00:05.000000000 -0400
<at> <at> -49,6 +49,8 <at> <at>
 
 // set timeout for socket
 stream_set_timeout($fp, 30);
+stream_set_blocking($fp, TRUE);
+$info = stream_get_meta_data($fp);
 
 // send request
 $out  = "GET $path HTTP/1.0\r\n";
<at> <at> -59,7 +61,8 <at> <at>
 // read response
 $header = true;
 $headers = array();
-while (!feof($fp)) {
+while ((!feof($fp)) && (!$info['timed_out'])) {
     $line = trim(fgets($fp, 4048));
 
     if ($header) {
<at> <at> -78,6 +81,7 <at> <at>
     else {
         $source .= "$line\n";
     }
+   $info = stream_get_meta_data($fp);
 }
 fclose($fp);
 

-Krishna
_______________________________________________
Roundcube Users mailing list
users@...
http://lists.roundcube.net/mailman/listinfo/users

Gmane