1
0
mirror of https://github.com/redis/node-redis.git synced 2025-08-06 02:15:48 +03:00

Handle very big pipelines without crashing

This commit is contained in:
Ruben Bridgewater
2016-03-01 16:57:32 +01:00
parent cc540dbc3c
commit 89209b8adc
2 changed files with 30 additions and 3 deletions

View File

@@ -106,7 +106,7 @@ function RedisClient (options) {
this.times_connected = 0;
this.options = options;
// Init parser
this.reply_parser = new Parser({
this.reply_parser = Parser({
returnReply: function (data) {
self.return_reply(data);
},
@@ -786,8 +786,13 @@ RedisClient.prototype.send_command = function (command, args, callback) {
};
RedisClient.prototype.writeDefault = RedisClient.prototype.writeStrings = function (data) {
var command, str = '';
while (command = this.pipeline_queue.shift()) {
var str = '';
for (var command = this.pipeline_queue.shift(); command; command = this.pipeline_queue.shift()) {
// Write to stream if the string is bigger than 4mb. The biggest string may be Math.pow(2, 28) - 15 chars long
if (str.length + command.length > 4 * 1024 * 1024) {
this.stream.write(str);
str = '';
}
str += command;
}
this.should_buffer = !this.stream.write(str + data);

View File

@@ -70,6 +70,28 @@ describe("The 'multi' method", function () {
});
});
describe('pipeline limit', function () {
it('do not exceed maximum string size', function (done) {
this.timeout(12000); // Windows tests on 0.10 are slow
// Triggers a RangeError: Invalid string length if not handled properly
client = redis.createClient();
var multi = client.multi();
var i = Math.pow(2, 28);
while (i > 0) {
i -= 10230;
multi.set('foo' + i, 'bar' + new Array(1024).join('1234567890'));
}
client.on('ready', function () {
multi.exec(function (err, res) {
assert.strictEqual(res.length, 26241);
});
client.flushdb(done);
});
});
});
helper.allTests(function(parser, ip, args) {
describe("using " + parser + " and " + ip, function () {