Fix the max-prefix freeze at rival exchanges and keep the loop alive
The max-prefix incident looked up an exchange id as a city, the same bug as #24. Both messages now name the exchange and its city. frame() now schedules the next frame first and catches a failing day tick or draw, so one bad lookup shows a warning instead of freezing the game.
This commit is contained in:
parent
16e1f95d1b
commit
988e0c5d15
3 changed files with 31 additions and 6 deletions
|
|
@ -6,6 +6,12 @@ All notable changes to this project are documented here. The project follows
|
|||
|
||||
## [Unreleased]
|
||||
|
||||
- The game no longer freezes when a peer drops you at a rival exchange
|
||||
(#24, thanks @daniloctdev), or when a route leak melts down one. The
|
||||
messages now name the exchange and its city.
|
||||
- One failing day no longer freezes the whole game: the error is caught,
|
||||
you get a heads-up, and time keeps running.
|
||||
|
||||
## [1.10.0] — 2026-10-24
|
||||
|
||||
- Router ports are finite. Every transit, IX, PNI and cache port, every wave
|
||||
|
|
|
|||
|
|
@ -1766,7 +1766,7 @@ function fireFailure(){
|
|||
addInc({type,ref:c,until:pp.down,msg:msg+(type==='oops'&&(pp.routers||1)>=2?' Automation pushed it to every router, so redundancy did not help.':''),cost:1500,fix:type==='oops'?'Roll back the config':'Hide the vacuum'});
|
||||
}else if(type==='maxpfx'){
|
||||
const c=pick(Object.keys(S.ixp));S.ev.ixdown=S.ev.ixdown||{};S.ev.ixdown[c]=Math.max(S.ev.ixdown[c]||0,S.day+1+Math.floor(Math.random()*2));
|
||||
addInc({type,ref:c,until:S.ev.ixdown[c],msg:`A member at ${ixName(c)} leaked the full routing table into the route server. Max-prefix limits tripped everywhere. Peering in ${CITY[c].name} is down.`,cost:0});
|
||||
addInc({type,ref:c,until:S.ev.ixdown[c],msg:`A member at ${ixName(c)} leaked the full routing table into the route server. Max-prefix limits tripped everywhere. Your peering there, in ${CITY[ixCity(c)].name}, is down.`,cost:0});
|
||||
}else if(type==='prepend'){
|
||||
const t=pick(S.transit);t.down=Math.max(t.down||0,S.day+2);addInc({type,ref:t.id,until:t.down,msg:`${NET[t.net].name} fat-fingered a route-map and prepended your AS ${30+Math.floor(Math.random()*60)} times in ${CITY[t.city].name}. Nobody wants that path.`,cost:0});
|
||||
}else if(type==='rpki'){
|
||||
|
|
@ -1889,7 +1889,7 @@ function dayTick(){
|
|||
if(R&&R.demand>0)S.stats.clean=R.served/R.demand>=0.995?(S.stats.clean||0)+1:0;
|
||||
if(S.ev.php===d)toast('<b>The internet is back.</b><br>Half of it, anyway. Everything was patched in a hurry and nobody learned anything.','good');
|
||||
for(const k in S.peers){const [id,c]=k.split('@'),sn=snub(id,c);if(!sn)continue;delete S.peers[k];S.stats.depeered=(S.stats.depeered||0)+1;
|
||||
toast(`<b>${esc(NET[id].name)} de-peered you in ${esc(CITY[ixCity(c)].name)}.</b><br>${esc(sn.why)} Traffic falls back to your next best path.`,'bad');}
|
||||
toast(`<b>${esc(NET[id].name)} de-peered you at ${esc(ixName(c))} in ${esc(CITY[ixCity(c)].name)}.</b><br>${esc(sn.why)} Traffic falls back to your next best path.`,'bad');}
|
||||
if(S.cnLic&&S.cnLic.state==='pending'&&d>=S.cnLic.ready){S.cnLic.state='ok';toast('<b>License granted!</b><br>Your joint venture can now build POPs in mainland China.','goal');sfx('coin');}
|
||||
// resolve incidents
|
||||
for(const i of S.inc.slice())if(i.until<=d){clearInc(i);toast(`<b>Resolved:</b> ${incTitle(i.type).toLowerCase()} is fixed.`,'good');}
|
||||
|
|
@ -3007,15 +3007,18 @@ document.addEventListener('click',e=>{const b=e.target.closest('[data-act]');if(
|
|||
/* ================= LOOP ================= */
|
||||
let last=performance.now(),acc=0,hudT=0,animT=0;
|
||||
function frame(now){
|
||||
// Schedule the next frame first: one bad lookup in a day tick must not freeze the whole game.
|
||||
if(!window.__TUBES_TEST__)requestAnimationFrame(frame);
|
||||
const dt=Math.min(250,now-last);last=now;
|
||||
if(ANALYTICS.host&&S&&!S.lost&&UI.speed&&document.visibilityState==='visible'){UI.playMs=(UI.playMs||0)+dt;const m=UI.playMs/60000;for(const k of PLAY_MARKS)if(m>=k)track('play_'+k+'m',true);}
|
||||
if(S&&UI.started&&!S.lost&&now-(UI.lastSave||0)>5000)save();
|
||||
if(S&&!S.lost&&$('modal').hidden&&UI.speed){acc+=dt*UI.speed;let n=0;while(acc>=DAY_MS&&n<4){acc-=DAY_MS;dayTick();n++;}
|
||||
if(S&&!S.lost&&$('modal').hidden&&UI.speed){acc+=dt*UI.speed;let n=0;while(acc>=DAY_MS&&n<4){acc-=DAY_MS;try{dayTick();}catch(e){tickErr(e);}n++;}
|
||||
if(n){renderHUD();if(!pressing){renderPanel();renderLeft();if(!$('dash').hidden)renderDash();renderBank();}renderHint();}}
|
||||
if(UI.speed&&!(S&&S.lost))animT+=dt; /* paused = frozen dots, waves and clouds */
|
||||
draw(animOn()?animT:0);
|
||||
if(!window.__TUBES_TEST__)requestAnimationFrame(frame);
|
||||
try{draw(animOn()?animT:0);}catch(e){tickErr(e);}
|
||||
}
|
||||
function tickErr(e){console.error('[tubes] tick failed',e);if(UI.tickErr)return;UI.tickErr=true;track('tick_error',true);
|
||||
toast('<b>Something in the NOC glitched.</b><br>The game kept going. If things look odd, export your save and open an issue on GitHub.','bad');}
|
||||
function boot(data){
|
||||
try{UI.muted=localStorage.getItem('sot-mute')==='1';UI.anim=localStorage.getItem('sot-anim')||'auto';}catch(e){}
|
||||
applyAnim();
|
||||
|
|
|
|||
|
|
@ -121,6 +121,22 @@ test('a peer at a rival exchange can de-peer you without stopping the game', ()
|
|||
ev(`S.peers['ggl@${ix}']=true;window.snub=()=>({why:'Testing.'})`);
|
||||
ev('dayTick()');
|
||||
assert.equal(ev(`'ggl@${ix}' in S.peers`), false);
|
||||
assert.match(ev("document.getElementById('toasts').textContent"), new RegExp(`de-peered you in ${ev(`CITY[ixCity('${ix}')].name`)}`));
|
||||
assert.match(ev("document.getElementById('toasts').textContent"), new RegExp(`de-peered you at ${ev(`ixName('${ix}')`)} in ${ev(`CITY[ixCity('${ix}')].name`)}`));
|
||||
assert.deepEqual(errors, []);
|
||||
});
|
||||
|
||||
test('an IX meltdown at a rival exchange names the city, and a failing day tick does not stop the game', () => {
|
||||
const { ev, errors } = load();
|
||||
ev("ACT.start({});S.cash=1e8;ACT.buildPop({city:'ams'});ACT.buyIx({city:'ams~2',tier:1});S.day=100");
|
||||
const src = ev('fireFailure.toString()').replace(/^function fireFailure/, 'function')
|
||||
.replace('let tot=opts.reduce', "opts.splice(0,opts.length,['funny',1]);let tot=opts.reduce")
|
||||
.replace('type=pick(f);}', "type='maxpfx';}");
|
||||
ev('window.__ff=' + src);
|
||||
ev('__ff()');
|
||||
assert.match(ev("S.inc.find(i=>i.type==='maxpfx').msg"), /in Amsterdam, is down/);
|
||||
// a tick that throws is caught, reported once, and the loop keeps going
|
||||
ev("const dt0=dayTick;window.dayTick=()=>{throw new Error('boom')};UI.speed=1;acc=DAY_MS;last=0;frame(16);window.dayTick=dt0");
|
||||
assert.equal(ev('UI.tickErr'), true);
|
||||
assert.match(ev("document.getElementById('toasts').textContent"), /NOC glitched/);
|
||||
assert.deepEqual(errors.filter(e => !/tick failed/.test(e)), []);
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue