Commit b9175a2c authored by Quentin Raynaud's avatar Quentin Raynaud

Restore the correct domain before calling the user callback

parent 4e8e6418
......@@ -255,6 +255,7 @@ Client.config = {
this.activeQueries++;
var query = queryCompiler();
query.domain = process.domain;
if (this.activeQueries> this.maxQueueSize && this.maxQueueSize > 0){
this.makeCallback(query.callback, "over queue limit", null);
......@@ -662,9 +663,17 @@ Client.config = {
}
};
memcached.delegateCallback = function(){
memcached.delegateCallback = function(master){
// restore domain if needed
if (master.domain) {
master.domain.enter();
}
else {
while (process.domain) {
process.domain.exit();
}
}
this.activeQueries--;
var master = arguments[0];
var cb = arguments[arguments.length-1];
var args = Array.prototype.slice.call(arguments, 1, arguments.length-1);
cb.apply(master, args);
......
/**
* Test dependencies
*/
var assert = require('assert')
, common = require('./common')
, Memcached = require('../')
, domain = require('domain');
global.testnumbers = global.testnumbers || +(Math.random(10) * 1000000).toFixed();
/**
* Expresso test suite for domain handling
*/
describe("Memcached domain awareness", function() {
var memcached = new Memcached(common.servers.single);
it('should restore the domain properly after each calls', function(done) {
var message = common.alphabet(256)
, testnr = ++global.testnumbers
, dA = domain.createDomain()
, dB = domain.createDomain();
dA.enter(); // enter domain A
memcached.set('test:' + testnr, message, 1000, function (error, ok) {
dB.enter(); // enter domain B
memcached.set('test:' + testnr, message, 1000, function (error, ok) {
// Leave all domains
while (process.domain) {
process.domain.exit();
}
done();
});
});
});
it('should not enter a domain when there is none', function(done) {
var message = common.alphabet(256)
, testnr = ++global.testnumbers;
assert.equal(process.domain, undefined);
memcached.set('test:' + testnr, message, 1000, function (error, ok) {
assert.equal(process.domain, undefined);
memcached.end(); // close connections
done();
});
});
});
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment