errorception / redis-lock

Implements a locking primitive using redis. An implementation of the algorithm described at https://redis.io/commands/setnx
211 stars 48 forks source link

Fixed concurrency bug #4

Closed pomarec closed 12 years ago

pomarec commented 12 years ago

If another client del the key between setnx and get, it triggered a wait of lockTimeout seconds, not anymore.

rakeshpai commented 12 years ago

Thanks for the pull request, @pomarec. For some reason, Github didn't give me notifications about your pull request, or else I would have merged it earlier. Thanks a ton!

rakeshpai commented 12 years ago

@pomarec I realise I'm asking for a bit much, but can you also provide a test that demonstrates how it was broken before your patch? It'll be a huge help.

pomarec commented 12 years ago

I'm sorry to tell you that I could not write a good test for this issue. This is what I came up with but I can't make it "bug".

it("shouldn't delay the second operation longer than the timeout value (100ms)", function(done) {
    var start = new Date();
    lock("testLock", 100, function(completed) {
        var lockDate = new Date().getTime();
        lock("testLock", 100, function(completed2) {
            var unlockDate = new Date().getTime();
            (unlockDate - lockDate).should.be.below(5000);
            completed2();
            done();
        });
        completed();
    });
});
rakeshpai commented 11 years ago

Ignore the last message Brain fart.