Skip to content

Commit

Permalink
Fixed parser not being reset in case the redis connection
Browse files Browse the repository at this point in the history
closed ASAP for overcoming of output buffer limits.

Fixes redis#1190
  • Loading branch information
Ruben Bridgewater committed Jan 15, 2017
1 parent dffa8a6 commit db0e8c5
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down
18 changes: 18 additions & 0 deletions test/node_redis.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down

0 comments on commit db0e8c5

Please sign in to comment.