From b7ca39715d173c50da51b8c710bc2b2a0591194e Mon Sep 17 00:00:00 2001 From: ansuz Date: Wed, 5 Feb 2020 13:03:11 -0500 Subject: [PATCH 1/2] 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 9609e7b51..ddcb8764f 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); })); @@ -749,7 +751,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(); } @@ -869,7 +870,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]]; From 14a67b560025e654831bee04a569c0376cc26ad5 Mon Sep 17 00:00:00 2001 From: ansuz Date: Wed, 5 Feb 2020 13:03:44 -0500 Subject: [PATCH 2/2] fix broken removePins RPC --- lib/commands/pin-rpc.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/commands/pin-rpc.js b/lib/commands/pin-rpc.js index 16998b8b5..663faa58b 100644 --- a/lib/commands/pin-rpc.js +++ b/lib/commands/pin-rpc.js @@ -199,7 +199,8 @@ Pinning.removePins = function (Env, safeKey, cb) { status: err? String(err): 'SUCCESS', }); - cb(err); + if (err) { return void cb(err); } + cb(void 0, 'OK'); }); };