You've already forked node-redis
mirror of
https://github.com/redis/node-redis.git
synced 2025-08-06 02:15:48 +03:00
Fix parser regression. Out of memory resulted in an endless loop
This commit is contained in:
@@ -220,6 +220,11 @@ ReplyParser.prototype._packetEndOffset = function () {
|
|||||||
|
|
||||||
while (this._buffer[offset] !== 0x0d && this._buffer[offset + 1] !== 0x0a) {
|
while (this._buffer[offset] !== 0x0d && this._buffer[offset + 1] !== 0x0a) {
|
||||||
offset++;
|
offset++;
|
||||||
|
|
||||||
|
/* istanbul ignore if: activate the js parser out of memory test to test this */
|
||||||
|
if (offset >= this._buffer.length) {
|
||||||
|
throw new IncompleteReadBuffer("didn't see LF after NL reading multi bulk count (" + offset + " => " + this._buffer.length + ", " + this._offset + ")");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
offset++;
|
offset++;
|
||||||
|
@@ -2,6 +2,8 @@
|
|||||||
|
|
||||||
var assert = require('assert');
|
var assert = require('assert');
|
||||||
var Parser = require("../../lib/parser/javascript").Parser;
|
var Parser = require("../../lib/parser/javascript").Parser;
|
||||||
|
var config = require("../lib/config");
|
||||||
|
var redis = config.redis;
|
||||||
|
|
||||||
describe('javascript parser', function () {
|
describe('javascript parser', function () {
|
||||||
it('handles multi-bulk reply', function (done) {
|
it('handles multi-bulk reply', function (done) {
|
||||||
@@ -24,4 +26,36 @@ describe('javascript parser', function () {
|
|||||||
assert.equal(reply_count, 3, "check reply should have been called three times");
|
assert.equal(reply_count, 3, "check reply should have been called three times");
|
||||||
return done();
|
return done();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Activate this if you want to fry your cpu / memory
|
||||||
|
describe.skip("test out of memory", function () {
|
||||||
|
var args = config.configureClient('javascript', '127.0.0.1');
|
||||||
|
var clients = new Array(300).join(" ").split(" ");
|
||||||
|
var client;
|
||||||
|
beforeEach(function (done) {
|
||||||
|
client = redis.createClient.apply(redis.createClient, args);
|
||||||
|
client.once("connect", function () {
|
||||||
|
client.flushdb(done);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('reach limit and wait for further data', function (done) {
|
||||||
|
setTimeout(done, 5000);
|
||||||
|
clients.forEach(function(entry, a) {
|
||||||
|
var max = 0;
|
||||||
|
var client = redis.createClient.apply(redis.createClient, args);
|
||||||
|
client.on('ready', function() {
|
||||||
|
while (++max < 50) {
|
||||||
|
var item = [];
|
||||||
|
for (var i = 0; i < 100; ++i) {
|
||||||
|
item.push('aaa' + (Math.random() * 1000000 | 0));
|
||||||
|
}
|
||||||
|
client.del('foo' + a);
|
||||||
|
client.lpush('foo' + a, item);
|
||||||
|
client.lrange('foo' + a, 0, 99);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
Reference in New Issue
Block a user