yeah, adapter errors (like out of storage) should not affect sync/networking logic, that was a bad experiment

This commit is contained in:
Mark Nadal 2021-05-14 18:39:42 -07:00
parent 8591d34be5
commit 7da46d1961
4 changed files with 36 additions and 21 deletions

6
gun.js
View File

@ -327,7 +327,7 @@
kl = Object.keys(node||{}); // TODO: .keys( is slow
}
if(err){
ctx.err = err;
msg.err = ctx.err = err; // invalid data should error and stun the message.
fire(ctx);
//console.log("handle error!", err) // handle!
//ctx.hatch && ctx.hatch(); // TODO: rename/rework how put & this interact.
@ -398,7 +398,7 @@
}
function ack(msg){ // aggregate ACKs.
var id = msg['@'] || '', root = (msg.$._||'').root, tmp;
if(msg.err && root && (tmp = root.dup.s[id])){ tmp.err = msg.err; } // add error to original message.
// TODO: check for the sharded message err and transfer it onto the original batch?
if(!(tmp = id._)){ /*console.log("TODO: handle ack id.");*/ return }
tmp.acks = (tmp.acks||0) + 1;
if(0 == tmp.stun && tmp.acks == tmp.all){ // TODO: if ack is synchronous this may not work?
@ -1330,7 +1330,7 @@
var DBG = msg.DBG, S = +new Date; meta.y = meta.y || S; if(!peer){ DBG && (DBG.y = S) }
if(!(id = msg['#'])){ id = msg['#'] = String.random(9) }
!loop && dup_track(id);//.it = it(msg); // track for 9 seconds, default. Earth<->Mars would need more! // always track, maybe move this to the 'after' logic if we split function.
if(msg.put && (msg.err || (dup.s[id]||'').err)){ return false } // stop relaying a invalid message, like failed SEA.
if(msg.put && (msg.err || (dup.s[id]||'').err)){ return false } // TODO: in theory we should not be able to stun a message, but for now going to check if it can help network performance preventing invalid data to relay.
if(!(hash = msg['##']) && u !== msg.put && !meta.via && ack){ mesh.hash(msg, peer); return } // TODO: Should broadcasts be hashed?
DBG && (DBG.yh = +new Date);
if(!(raw = meta.raw)){ mesh.raw(msg, peer); return }

4
sea.js
View File

@ -1204,10 +1204,10 @@
})})
return
}
var no = function(why){ at.on('in', {'@': id, err: why}) };
var no = function(why){ at.on('in', {'@': id, err: msg.err = why}) }; // exploit internal relay stun for now, maybe violates spec, but testing for now. // Note: this may be only the sharded message, not original batch.
//var no = function(why){ msg.ack(why) };
(msg._||'').DBG && ((msg._||'').DBG.c = +new Date);
if(0 <= soul.indexOf('<?')){ // special case for "do not sync data X old"
if(0 <= soul.indexOf('<?')){ // special case for "do not sync data X old" forget
// 'a~pub.key/b<?9'
tmp = parseFloat(soul.split('<?')[1]||'');
if(tmp && (state < (Gun.state() - (tmp * 1000)))){ // sec to ms

View File

@ -7744,22 +7744,7 @@ describe('Gun', function(){
});
});
it("localStorage", function(done){
var localStorage = localStorage || {clear:function(){}};
localStorage.clear();
var gun = Gun();
var text = Gun.text.random(1024 * 1024 * 6);
gun.put({i: text}, function(err, ok){
if(done.c){ return }
if(!err){ return done() }
var text = "If you are seeing this message, it means the localStorage error was caught successfully rather than it crashing and stopping replication to peers. Also, the error is now reported back to you via the put callback. Here it is!";
localStorage.clear();
done(); done.c = 1;
});
});
it("get context", function(done){ // TODO: HUH?????? This was randomly causing errors?
var gun = Gun();
var ref = gun.get('ctx/lol').get('ctx/foo').put({hello: 'world'});
@ -8004,6 +7989,34 @@ describe('Gun', function(){
*/
});
describe('localStorage', function(){
it("err", function(done){
var localStorage = localStorage || {clear:function(){}};
localStorage.clear();
var gun = Gun();
var text = String.random(1024 * 1024 * 6);
gun.put({i: text}, function(ack){
var err = ack.err, ok = ack.ok;
if(done.c){ return }
if(!err){ return done() }
var text = "If you are seeing this message, it means the localStorage error was caught successfully rather than it crashing and stopping replication to peers. Also, the error is now reported back to you via the put callback. Here it is!";
localStorage.clear();
done(); done.c = 1;
});
});
it("ack", function(done){
var localStorage = localStorage || {clear:function(){}};
localStorage.clear();
var gun = Gun();
var i = 999, obj = {}; while(--i){ obj[i] = String.random(99) }
//console.log("save:", obj);
gun.get('lSack').put(obj, function(ack){
//console.log("ack:", ack)
done(); done.c = 1;
});
});
});
describe('Streams', function(){
console.log("TODO: BUG! Upgrade UNION tests to new internal API!");
return;

View File

@ -4,6 +4,7 @@ var config = {
servers: 1,
browsers: 2, //3,
each: 100000,
size: 1,
wait: 1,
route: {
'/': __dirname + '/index.html',
@ -132,12 +133,13 @@ describe("Load test "+ config.browsers +" browser(s) across "+ config.servers +"
var rand = String.random || Gun.text.random;
var i = test.props.each, chat = {}, S = Gun.state();
var tmp = "generating " + i + " records..."; console.log(tmp); $('b').text(tmp);
var big = rand(test.props.size || 1); //1000 * 10);
function gen(){
var j = 99;
$('b').text(i + ' left to generate...');
var data = rand(100);
while(--j && i){ --i;
Gun.state.ify(chat, i/*+'-'+rand(9)*/, S, rand(100) + data, 'chat');
Gun.state.ify(chat, i/*+'-'+rand(9)*/, S, rand(100) + data + big, 'chat');
}
if(i === 0){
gun._.graph.chat = chat;