From 0c172f425cc43ef9c8cb3f6a91eb0eec0461b80e Mon Sep 17 00:00:00 2001 From: Bryce Baril Date: Sat, 23 Feb 2013 19:20:30 -0800 Subject: [PATCH] Fix parser incorrect buffer skip for MULTI/EXEC transaction errors with WATCH. Signed-off-by: DTrejo --- lib/parser/javascript.js | 3 +-- test.js | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/lib/parser/javascript.js b/lib/parser/javascript.js index 256c3ea9ad..7bfdb57edf 100644 --- a/lib/parser/javascript.js +++ b/lib/parser/javascript.js @@ -117,7 +117,6 @@ ReplyParser.prototype._parseResult = function (type) { } if (packetHeader.size < 0) { - this._offset += 2; return null; } @@ -295,4 +294,4 @@ ReplyParser.prototype.send_error = function (reply) { ReplyParser.prototype.send_reply = function (reply) { this.emit("reply", reply); -}; \ No newline at end of file +}; diff --git a/test.js b/test.js index 5d0d4a692f..c8a9843654 100644 --- a/test.js +++ b/test.js @@ -454,6 +454,41 @@ tests.WATCH_MULTI = function () { multi.exec(last(name, require_null(name))); }; +tests.WATCH_TRANSACTION = function () { + var name = "WATCH_TRANSACTION"; + + if (!server_version_at_least(client, [2, 1, 0])) { + console.log("Skipping " + name + " because server version isn't new enough."); + return next(name); + } + + // Test WATCH command aborting transactions, look for parser offset errors. + + client.set("unwatched", 200); + + client.set(name, 0); + client.watch(name); + client.incr(name); + var multi = client.multi() + .incr(name) + .exec(function (err, replies) { + // Failure expected because of pre-multi incr + assert.strictEqual(replies, null, "Aborted transaction multi-bulk reply should be null."); + + client.get("unwatched", function (err, reply) { + assert.equal(err, null, name); + assert.equal(reply, 200, "Expected 200, got " + reply); + next(name); + }); + }); + + client.set("unrelated", 100, function (err, reply) { + assert.equal(err, null, name); + assert.equal(reply, "OK", "Expected 'OK', got " + reply); + }); +}; + + tests.detect_buffers = function () { var name = "detect_buffers", detect_client = redis.createClient(null, null, {detect_buffers: true});