From db0e8c53cc7a68e65b591dc2e457b5a7e7f5065b Mon Sep 17 00:00:00 2001 From: Ruben Bridgewater Date: Sun, 15 Jan 2017 13:09:15 +0100 Subject: [PATCH] Fixed parser not being reset in case the redis connection closed ASAP for overcoming of output buffer limits. Fixes #1190 --- changelog.md | 1 + index.js | 5 +++-- test/node_redis.spec.js | 18 ++++++++++++++++++ 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/changelog.md b/changelog.md index 3b0e7b8cfc..ee7b4c9d23 100644 --- a/changelog.md +++ b/changelog.md @@ -5,6 +5,7 @@ Changelog Bugfixes +- Fixed parser not being reset in case the redis connection closed ASAP for overcoming of output buffer limits - Fixed parser reset if (p)message_buffer listener is attached ## v.2.6.4 - 12 Jan, 2017 diff --git a/index.js b/index.js index 1b094f90b6..f587bea577 100644 --- a/index.js +++ b/index.js @@ -156,8 +156,6 @@ function RedisClient (options, stream) { this.buffers = options.return_buffers || options.detect_buffers; this.options = options; this.reply = 'ON'; // Returning replies is the default - // Init parser - this.reply_parser = create_parser(this); this.create_stream(); // The listeners will not be attached right away, so let's print the deprecation message while the listener is attached this.on('newListener', function (event) { @@ -230,6 +228,9 @@ function create_parser (self) { RedisClient.prototype.create_stream = function () { var self = this; + // Init parser + this.reply_parser = create_parser(this); + if (this.options.stream) { // Only add the listeners once in case of a reconnect try (that won't work) if (this.stream) { diff --git a/test/node_redis.spec.js b/test/node_redis.spec.js index e6e5f0987f..64be131bba 100644 --- a/test/node_redis.spec.js +++ b/test/node_redis.spec.js @@ -38,6 +38,24 @@ describe('The node_redis client', function () { client.quit(done); }); + it('reset the parser while reconnecting', function (done) { + var client = redis.createClient({ + retryStrategy: function () { + return 5; + } + }); + client.once('reconnecting', function () { + process.nextTick(function () { + assert.strictEqual(client.reply_parser.buffer, null); + done(); + }); + }); + var partialInput = new Buffer('$100\r\nabcdef'); + client.reply_parser.execute(partialInput); + assert.strictEqual(client.reply_parser.buffer.inspect(), partialInput.inspect()); + client.stream.destroy(); + }); + helper.allTests(function (parser, ip, args) { describe('using ' + parser + ' and ' + ip, function () {