Skip to content

Commit db0e8c5

Browse files
author
Ruben Bridgewater
committed
Fixed parser not being reset in case the redis connection
closed ASAP for overcoming of output buffer limits. Fixes #1190
1 parent dffa8a6 commit db0e8c5

File tree

3 files changed

+22
-2
lines changed

3 files changed

+22
-2
lines changed

changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ Changelog
55

66
Bugfixes
77

8+
- Fixed parser not being reset in case the redis connection closed ASAP for overcoming of output buffer limits
89
- Fixed parser reset if (p)message_buffer listener is attached
910

1011
## v.2.6.4 - 12 Jan, 2017

index.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,8 +156,6 @@ function RedisClient (options, stream) {
156156
this.buffers = options.return_buffers || options.detect_buffers;
157157
this.options = options;
158158
this.reply = 'ON'; // Returning replies is the default
159-
// Init parser
160-
this.reply_parser = create_parser(this);
161159
this.create_stream();
162160
// The listeners will not be attached right away, so let's print the deprecation message while the listener is attached
163161
this.on('newListener', function (event) {
@@ -230,6 +228,9 @@ function create_parser (self) {
230228
RedisClient.prototype.create_stream = function () {
231229
var self = this;
232230

231+
// Init parser
232+
this.reply_parser = create_parser(this);
233+
233234
if (this.options.stream) {
234235
// Only add the listeners once in case of a reconnect try (that won't work)
235236
if (this.stream) {

test/node_redis.spec.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,24 @@ describe('The node_redis client', function () {
3838
client.quit(done);
3939
});
4040

41+
it('reset the parser while reconnecting', function (done) {
42+
var client = redis.createClient({
43+
retryStrategy: function () {
44+
return 5;
45+
}
46+
});
47+
client.once('reconnecting', function () {
48+
process.nextTick(function () {
49+
assert.strictEqual(client.reply_parser.buffer, null);
50+
done();
51+
});
52+
});
53+
var partialInput = new Buffer('$100\r\nabcdef');
54+
client.reply_parser.execute(partialInput);
55+
assert.strictEqual(client.reply_parser.buffer.inspect(), partialInput.inspect());
56+
client.stream.destroy();
57+
});
58+
4159
helper.allTests(function (parser, ip, args) {
4260

4361
describe('using ' + parser + ' and ' + ip, function () {

0 commit comments

Comments
 (0)