From a00a9fd018f7eb4388e823d8bd023559b283754a Mon Sep 17 00:00:00 2001 From: ansuz Date: Wed, 5 Feb 2020 13:03:11 -0500 Subject: [PATCH] don't hang when reading unparseable lines from history --- lib/historyKeeper.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/historyKeeper.js b/lib/historyKeeper.js index b0f06e2fe..ff7b531e9 100644 --- a/lib/historyKeeper.js +++ b/lib/historyKeeper.js @@ -595,7 +595,9 @@ module.exports.create = function (cfg, cb) { const start = (beforeHash) ? 0 : offset; store.readMessagesBin(channelName, start, (msgObj, readMore, abort) => { if (beforeHash && msgObj.offset >= offset) { return void abort(); } - handler(tryParse(msgObj.buff.toString('utf8')), readMore); + var parsed = tryParse(msgObj.buff.toString('utf8')); + if (!parsed) { return void readMore(); } + handler(parsed, readMore); }, waitFor(function (err) { return void cb(err); })); @@ -747,7 +749,6 @@ module.exports.create = function (cfg, cb) { // TODO compute lastKnownHash in a manner such that it will always skip past the metadata line? getHistoryAsync(channelName, lastKnownHash, false, (msg, readMore) => { - if (!msg) { return; } // XXX msgCount++; // avoid sending the metadata message a second time if (isMetadataMessage(msg) && metadata_cache[channelName]) { return readMore(); } @@ -866,7 +867,6 @@ module.exports.create = function (cfg, cb) { // FIXME should we send metadata here too? // none of the clientside code which uses this API needs metadata, but it won't hurt to send it (2019-08-22) return void getHistoryAsync(parsed[1], -1, false, (msg, readMore) => { - if (!msg) { return; } Server.send(userId, [0, HISTORY_KEEPER_ID, 'MSG', userId, JSON.stringify(['FULL_HISTORY', msg])], readMore); }, (err) => { let parsedMsg = ['FULL_HISTORY_END', parsed[1]];