Skip to content

Loading…

MemCache get callback called multiple times when MemCache can't connect #68

Closed
carystanley opened this Issue · 9 comments

6 participants

@carystanley

When 'get' is called on a MemCache Connection that is unable to connect to the MemCache server. The callback is being called multiple times with 'Connect did not give a server' as the first parameter.

This seems like the wrong behavior. The callback should really only be called once. If the fallback is to make a data request for the data that it was not able to retrieve from the cache, the current behavior causes multiple data requests to be continually made.

@3rd-Eden
Owner

That sounds really bad, do you have a broken test for this?

@morus12

When Memcached server is unavailable memcache.get callback is fired several times.

Memcached = require('memcached');
memcached = new Memcached('127.0.0.1:11212',{retries : 1});

memcached.get('key', function(err, val){
console.log(err);

});

Output:

Connect did not give a server
Connect did not give a server
Connect did not give a server
Connect did not give a server
Connect did not give a server
Connect did not give a server
{ [Error: connect ECONNREFUSE
code: 'ECONNREFUSED',
errno: 'ECONNREFUSED',
syscall: 'connect' }

@kaosdynamics

+1 that's exactly whats happenin to me... I tried to fix this issue by setting retries and even remove as true, seemed to be not working

@glynnbird

Pull request #69 doesn't prevent the callback being called multiple times.

Code such as this:

mc.get( "hello", function( err, result ){
if( err ) {
console.error( "GET ERROR",err );
} else {
console.log( "GET SUCCESS",result );
}
});

results in:

GET ERROR Connect did not give a server
GET ERROR Connect did not give a server
GET ERROR { [Error: connect ECONNREFUSED]
code: 'ECONNREFUSED',
errno: 'ECONNREFUSED',
syscall: 'connect' }

before applying the "retries" patch, I got:

GET ERROR Connect did not give a server
GET ERROR Connect did not give a server
GET ERROR Connect did not give a server
GET ERROR Connect did not give a server
GET ERROR Connect did not give a server
GET ERROR Connect did not give a server
GET ERROR Connect did not give a server
GET ERROR Connect did not give a server

This a pretty serious bug because it means if your memcached goes away, you end up fetching from your source data multiple times because the callback is called multiple times.

@3rd-Eden
Owner

@glynnbird I'm working on this, I hope to have something fixed tonight

@ronkorving
Collaborator

Any update on this?

@3rd-Eden
Owner

@ronkorving still working on this, but root of the issue is deeper then expected. Still trying to come up with a elegant solution for this..

@3rd-Eden 3rd-Eden added a commit that closed this issue
@3rd-Eden [fix] Don't emit the callback multiple times when shit goes wrong, fi…
…xes #68

The whole reconnection/failover logic should be redone, this is just silly..
82eb7c9
@3rd-Eden 3rd-Eden closed this in 82eb7c9
@3rd-Eden
Owner

If someone else could confirm that the fix above resolves their issues as well, I would be more than happy to do a release tomorrow.

@kaosdynamics

I believe this fix solves my issue. Thank you very much @3rd-Eden !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.