don't hang when reading unparseable lines from history

pull/1/head
ansuz 5 years ago
parent 3741cbcbc0
commit a00a9fd018

@ -595,7 +595,9 @@ module.exports.create = function (cfg, cb) {
const start = (beforeHash) ? 0 : offset; const start = (beforeHash) ? 0 : offset;
store.readMessagesBin(channelName, start, (msgObj, readMore, abort) => { store.readMessagesBin(channelName, start, (msgObj, readMore, abort) => {
if (beforeHash && msgObj.offset >= offset) { return void 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) { }, waitFor(function (err) {
return void cb(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? // TODO compute lastKnownHash in a manner such that it will always skip past the metadata line?
getHistoryAsync(channelName, lastKnownHash, false, (msg, readMore) => { getHistoryAsync(channelName, lastKnownHash, false, (msg, readMore) => {
if (!msg) { return; } // XXX
msgCount++; msgCount++;
// avoid sending the metadata message a second time // avoid sending the metadata message a second time
if (isMetadataMessage(msg) && metadata_cache[channelName]) { return readMore(); } 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? // 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) // 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) => { 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); Server.send(userId, [0, HISTORY_KEEPER_ID, 'MSG', userId, JSON.stringify(['FULL_HISTORY', msg])], readMore);
}, (err) => { }, (err) => {
let parsedMsg = ['FULL_HISTORY_END', parsed[1]]; let parsedMsg = ['FULL_HISTORY_END', parsed[1]];

Loading…
Cancel
Save