Roll20 uses cookies to improve your experience on our site. Cookies enable you to enjoy certain features, social sharing functionality, and tailor message and display ads to your interests on our site and others. They also help us understand how our site is being used. By continuing to use our site, you consent to our use of cookies. Update your cookie preferences .
×
Create a free account

Infinite Loop shutting down API happening all the time (including during games)

Hello everyone, Over the course of the last few weeks, I've been noticing an issue with my game "Aventures en Azéroth". I'm using a set of scripts :  ChatSetAttr PowerCards A custom script that I was sent via help of a community member that goes as follow :  on('ready',function(){ "use strict"; const checkFormulaOnTurn = () => { let to=JSON.parse(Campaign().get('turnorder')||'[]'); if(to.length && to[0].id==='-1'){ sendChat('',`[[${to[0].pr}+(${to[0].formula||0})]]`,(r)=>{ to[0].pr=r[0].inlinerolls[0].results.total; Campaign().set('turnorder',JSON.stringify(to)); }); } }; on('chat:message',function(msg){ var args,cmds,who,initial,change,entry; if('api' === msg.type) { if(msg.content.match(/^!act\b/) ){ who=(getObj('player',msg.playerid)||{get:()=>'API'}).get('_displayname'); if(_.has(msg,'inlinerolls')){ msg.content = _.chain(msg.inlinerolls) .reduce(function(m,v,k){ var ti=_.reduce(v.results.rolls,function(m2,v2){ if(_.has(v2,'table')){ m2.push(_.reduce(v2.results,function(m3,v3){ m3.push(v3.tableItem.name); return m3; },[]).join(', ')); } return m2; },[]).join(', '); m['$[['+k+']]']= (ti.length && ti) || v.results.total || 0; return m; },{}) .reduce(function(m,v,k){ return m.replace(k,v); },msg.content) .value(); } args = msg.content .replace(/<br\/>\n/g, ' ') .replace(/(\{\{(.*?)\}\})/g," $2 ") .split(/\s+--/); cmds=args.shift().split(/\s+/); change=parseFloat(cmds[1])||'+1'; change=`${/^[+-]\d/.test(change)?'':'+'}${change}`; initial=parseFloat(cmds[2])||0; entry=args.join(' '); if(entry.length){ let to=JSON.parse(Campaign().get('turnorder')||'[]'); to.unshift({ id: "-1", pr: initial, custom: entry, formula: change }); Campaign().set('turnorder',JSON.stringify(to)); if(!playerIsGM(msg.playerid)){ sendChat('ACT',`/w gm <div style="padding:1px 3px;border: 1px solid #8B4513;background: #eeffee; color: #8B4513; font-size: 80%;"><div style="background-color: #ffeeee;"><b>${who}</b> added entry for <b>${entry}</b> starting at <b>${initial}</b> and changing by <b>${change}</b>.</div></div>`); } } else { sendChat('ACT',`/w "${who}" <div style="padding:1px 3px;border: 1px solid #8B4513;background: #eeffee; color: #8B4513; font-size: 80%;"><div style="background-color: #ffeeee;">Use <b><pre>!act [formula] [starting value] --[description]</pre></b></div></div>`); } } else if(msg.content.match(/^!eot/i)){ _.defer(checkFormulaOnTurn); } } }); }); Anyway, the issue seems to be that either of these scripts causes an infinite loop that causes the API to shut down, which means asking the players to all disconnect from the game so that I can restart the API. I've had this issue happen before with ChatSetAttr, when a player without the appropriate rights would query the attributes of a character which they could not control. What would basically happen is that the macro wouldn't be displayed and a few minutes later, the API sandbox would shut down. However, I seemed to have fixed the issue over weeks of testing and correcting the typos in my macro and everything was working fine, until recently. I haven't changed anything, and the API will shut down just like that, because of a "possible infinite loop detected". It happens during my prep sessions, during the actual games, and in between. I know infinite loops have been a known issue, but is something else known about this? Like, maybe a new update to one of the scripts led to more possible infinite loops occurring. It's also worth mentioning I guess that both me and my players (spread out across France), have been encountering severe delays between clicking on a macro and it effectively running. Anyone with a helpful clue or comment would be immensely appreciated. Cheers and happy new year to all!
1644561781
Mike W.
Pro
Sheet Author
I too am seeing this happening. Different games with different scripts. At first I thought it was TokenMod causing the issue but The Aaron assured it was not. WI am using the GURPS character sheet (the first one), and the Console log shows no issues with the sheet when opening or closing it. When I restart the API I do see this: "SyntaxError: Unexpected token '?' at eval (<anonymous>) at messageHandler (evalmachine.<anonymous>:713:6) at process.<anonymous> (/home/node/d20-api-server/node_modules/tiny-worker/lib/worker.js:65:55) at process.emit (events.js:310:20) at emit (internal/child_process.js:876:12) at processTicksAndRejections (internal/process/task_queues.js:85:21)" However I have seem this reported in similar posts and the conclusion was that this was not the cause and is actually an issue you can ignore if the Character Sheet is working fine. Not sure what to try next.
1644911789
MadCoder
Pro
Sheet Author
Mike W. said: I too am seeing this happening. Different games with different scripts. At first I thought it was TokenMod causing the issue but The Aaron assured it was not. WI am using the GURPS character sheet (the first one), and the Console log shows no issues with the sheet when opening or closing it. When I restart the API I do see this: "SyntaxError: Unexpected token '?' at eval (<anonymous>) at messageHandler (evalmachine.<anonymous>:713:6) at process.<anonymous> (/home/node/d20-api-server/node_modules/tiny-worker/lib/worker.js:65:55) at process.emit (events.js:310:20) at emit (internal/child_process.js:876:12) at processTicksAndRejections (internal/process/task_queues.js:85:21)" However I have seem this reported in similar posts and the conclusion was that this was not the cause and is actually an issue you can ignore if the Character Sheet is working fine. Not sure what to try next. For the GURPS character sheet, I found the cause if the unexpected token error. There were a few statements that use the Nullish coalescing operator (??) , which is a way to check for null values, if null use a default value. Modern browsers support this operator and will not show an error. However, it appears that the API doesn't support this operator, as soon as I removed those operators the syntax error went away. I don't know what caused the infinite loop but the syntax will no longer be an issue.
1644938853
Mike W.
Pro
Sheet Author
Excellent!