Skip to content

Error during Memcached::get() masked by NOTFOUND #9

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
jhansche opened this issue Mar 27, 2012 · 4 comments
Closed

Error during Memcached::get() masked by NOTFOUND #9

jhansche opened this issue Mar 27, 2012 · 4 comments

Comments

@jhansche
Copy link

From pecl-memcached Bug #61466:

Description:

If an error occurs while attempting to perform a Memcached::get(), the result code will be set to RES_NOTFOUND. However, that result is actually masking the more important error (such as connection failure, timed out, server is marked dead, etc...)

Replacing the Memcached::get() call with a Memcached::set() call results in the correct result code being reported.

Test script:

<?php

$mc = new Memcached();
$mc->addServer('10.2.3.4', 5555); // Server should not exist

$mc->setOption( Memcached::OPT_RETRY_TIMEOUT, 1 );

while (true)
{
  // Note how it changes if you remove either the get() call or the set() call.
  // Having only get(), results in "NOT FOUND" printed repeatedly.

  $result = $mc->get('foo');
  echo var_export( $result, true ), "; ", $mc->getResultCode( ), ': ', $mc->getResultMessage( ), "\n";

  $result = $mc->set('foo', 1, 0);
  echo var_export( $result, true ), "; ", $mc->getResultCode( ), ': ', $mc->getResultMessage( ), "\n";

  usleep(250000);
}

Expected result:

false; 3: CONNECTION FAILURE
false; 35: SERVER IS MARKED DEAD
false; 35: SERVER IS MARKED DEAD
false; 35: SERVER IS MARKED DEAD
false; 35: SERVER IS MARKED DEAD
false; 35: SERVER IS MARKED DEAD
false; 35: SERVER IS MARKED DEAD
false; 35: SERVER IS MARKED DEAD
false; 3: CONNECTION FAILURE
false; 35: SERVER IS MARKED DEAD
false; 35: SERVER IS MARKED DEAD
false; 35: SERVER IS MARKED DEAD
false; 35: SERVER IS MARKED DEAD
false; 35: SERVER IS MARKED DEAD
false; 35: SERVER IS MARKED DEAD
false; 35: SERVER IS MARKED DEAD
false; 3: CONNECTION FAILURE
...

Actual result:

false; 16: NOT FOUND
false; 35: SERVER IS MARKED DEAD
false; 16: NOT FOUND
false; 35: SERVER IS MARKED DEAD
false; 16: NOT FOUND
false; 35: SERVER IS MARKED DEAD
false; 16: NOT FOUND
false; 35: SERVER IS MARKED DEAD
false; 16: NOT FOUND
false; 35: SERVER IS MARKED DEAD
false; 16: NOT FOUND
false; 35: SERVER IS MARKED DEAD
false; 16: NOT FOUND
false; 35: SERVER IS MARKED DEAD
false; 16: NOT FOUND
false; 35: SERVER IS MARKED DEAD
...

Additional Info

Try commenting out the get() lines and see that the expected result is achieved (because set() does not mask the error). And commenting out the set() lines results in only "NOT FOUND" being printed.

@maddok
Copy link

maddok commented Jun 12, 2012

This is painful and almost caused me to abandon the memcached plugin. I have managed to find a work-around that seems to be working well for me. When Requesting a $cas token when making the get request suddenly the expected error messaging is provided.

$result = $mc->get('foo', NULL, $cas );

I'm not sure why it silently just returns no result with just the get( ). Leaving a comment here in the hopes it helps someone else.

@naxhh
Copy link

naxhh commented Nov 5, 2012

Same here, $cas works and provides the correct message

@snstamml-tio
Copy link

Unfortunately, the $cas workaround doesn't work for all cases. A connection timeout still returns "NOT FOUND" instead of "TIMEOUT".

This is really bad, not only for debugging, but also for production error logging, because it's not possible to distinguish between a normal cache miss and an error condition.

@mkoppanen
Copy link
Member

Fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants