Comment 10 for bug 583031

Revision history for this message
peter mcarthur (ptrmcrthr) wrote :

I think the fix is incorrect for non-blocking connections. Now there is no timeout setting available for non-blocking connections to avoid a down server.

OPT_CONNECT_TIMEOUT is ignored, because of this section on line 22:

  int timeout= ptr->root->connect_timeout;
  if (ptr->root->flags.no_block == true)
    timeout= -1;
...
    error= poll(fds, 1, timeout);

I believe that makes the connect call blocking.

        $options = array(
                                                 Memcached::OPT_CONNECT_TIMEOUT => 1, // milliseconds
                                                 Memcached::OPT_POLL_TIMEOUT => 1, // milliseconds
                                                 Memcached::OPT_RECV_TIMEOUT => 1000, // usec
                                                 Memcached::OPT_SEND_TIMEOUT => 1000, // usec
        );

$m = new memcached();
$m->setOptions($options);
$m->addServer("192.168.7.9", "11211");

$start = microtime(true);
$m->get('test');
echo $m->getResultMessage() . " after " . (microtime(true) - $start) . "s \n";
$m->get('test');
echo $m->getResultMessage() . " after " . (microtime(true) - $start) . "s \n";
$m->get('test');
echo $m->getResultMessage() . " after " . (microtime(true) - $start) . "s \n";

$end = microtime(true);
echo $end - $start . "\n";

# With OPT_NO_BLOCK:
$ php ~/test-nonblocking.php
SYSTEM ERROR after 189.00634503365s
SYSTEM ERROR after 378.03397202492s
SYSTEM ERROR after 567.05481410027s
567.05880594254

# Without OPT_NO_BLOCK:
$ php ~/test-blocking.php
A TIMEOUT OCCURRED after 0.042192935943604s
A TIMEOUT OCCURRED after 0.074706792831421s
A TIMEOUT OCCURRED after 0.089533805847168s
0.089677810668945