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

Intermittent infinite loop issue

I'm running a 5e campaign and still using the old shaped sheet (which I realize is no longer supported by the author) and I'm running into some intermittent issues with it. As I drag a token to the table sometimes it will roll the health and set it to the appropriate token bar, and then without changing a thing occasionally I'll drag a token to the table and it will not react and I'll receive an error message that says "Possible infinite loop detected, shutting down."

From what I can tell the issue seems to spawn from this section of code:

sendChat('Shaped', '/roll ' + hdFormula, function (ops) {
log(ops);
var rollResult = JSON.parse(ops[0].content);
log(rollResult);
if (_.has(rollResult, 'total')) {
token.set(barTokenName + '_value', rollResult.total);
token.set(barTokenName + '_max', rollResult.total);
messageToChat('HP (' + hdFormulaChat + ') | average: ' + Math.floor(hdAverage) + ' | rolled: ' + rollResult.total);


But with the issue being intermittent I can't put my finger on an actual cause, any assistance would be appreciated. 
May 21 (9 years ago)
Hi, Jason, thanks for the bug report! The Roll20 Dev Team is aware of this issue, and will do their best to help as soon as possible.
May 21 (9 years ago)
Stephen Koontz
Forum Champion
Marketplace Creator
Sheet Author
API Scripter
Compendium Curator
Everything looks healthy on our end as far as I can tell. Is this a new issue that started tonight? Can you give me any other details? What script are you using or is it one of your own devising? 

Steve K. said:

Everything looks healthy on our end as far as I can tell. Is this a new issue that started tonight? Can you give me any other details? What script are you using or is it one of your own devising? 

Its been going on what looks like about two weeks now, the scripts that I'm using are the 5e-Scripts that Kryx created a while back. Along with a monster database and spell database. Happy to give you GM status on the game if it'll help. 
May 21 (9 years ago)
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
Not sure if it is related, but I have gotten this a couple of times in the last week and a half. It seemed to happen if I accidentally clicked the save script button before the sandbox finished loading up from the first save. I have no idea if this is actually related though.

Scott C. said:

Not sure if it is related, but I have gotten this a couple of times in the last week and a half. It seemed to happen if I accidentally clicked the save script button before the sandbox finished loading up from the first save. I have no idea if this is actually related though.

Sounds like a different issue, the sandbox fully loads and it happens once I drag a token onto the table.
I am also getting an infinite loop error.

I am using a GSA script that I can edit tokens with. I had gotten rid of all the references to the ammo script which I thought was the culprit but it still seems to error. What I am doing is editing attributes of characters for a town I am making. I set up a somewhat automated process to guide me through character creation. There are lots of buttons I am using. It would probably be best to set up some sort of character sheet for what I am doing but I do not understand the Java enough to do it yet.

I am going to redo some of my macros and see if the problem is that I have 2 references to the script in some of the macros when the script is meant to consolidate all the attribute changes to one chat command. 
If I only run the gsa scrip, and have only one instance of the command per macro, it seems to give the error a lot less. I was changing a lot of attribute values to zero with one macro, and changing more than one character sheet with the same macro. Here is a copy of the script I am using.
on('ready',function(){
    "use strict";

    var regex = {
        stripSingleQuotes: /'([^']+(?='))'/g,
        stripDoubleQuotes: /"([^"]+(?="))"/g
    };

    on('chat:message',function(msg){
        var args,errors=[],who,cmd,characterid,createAttrs,character;

        if('api' === msg.type && msg.content.match(/^!gsa\b/) ){

            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+--/);

            cmd=args.shift().split(/\s+/);
            characterid=_.last(cmd);
            createAttrs=_.contains(cmd,'-c');
            character=findObjs({
                type: 'character',
                id: characterid
            })[0];
            
            if(character){
                let control = character.get('controlledby').split(/,/);
                if(playerIsGM(msg.playerid) || _.contains(control,'all') || _.contains(control,msg.playerid)) {
                    _.chain(args)
                        .map(o=>{
                            let p=o.match(/("[^"]*"|'[^']'|.*?)[\|#]("[^"]*"|'[^']'|.*)/),
                            a,v;
                            if(p){
                                return {
                                    attrName: p[1],
                                    value: p[2].replace(regex.stripSingleQuotes,'$1').replace(regex.stripDoubleQuotes,'$1')
                                };
                            } else {
                                errors.push({
                                    type: 'BadArgument',
                                    value: o
                                });
                            }
                        })
                        .reject(_.isUndefined)
                        .map(o=>{
                            o.attr=findObjs({
                                type: 'attribute',
                                characterid: characterid,
                                name: o.attrName
                            })[0];
                            if(o.attr){
                                return o;
                            } else if(createAttrs){
                                createObj('attribute',{
                                    characterid: characterid,
                                    name: o.attrName,
                                    current: o.value
                                });
                            } else {
                                errors.push({
                                    type: 'MissingAttribute',
                                    value: o.attrName
                                });
                            }
                        })
                        .reject(_.isUndefined)
                        .each(o=>{
                            o.attr.set({
                                current: o.value
                            });
                        });
                } else {
                    errors.push({
                        type: 'NoCharacterAccess',
                        value: 'You are not allowed to access this character.'
                    });
                }
            } else {
                errors.push({
                    type: 'MissingCharacter',
                    value: characterid
                });
            }

            if(errors.length){
                who=getObj('player',msg.playerid).get('_displayname');

                sendChat('GSA',`/w "${who}" <div style="padding:1px 3px;border: 1px solid #8B4513;background: #eeffee; color: #8B4513; font-size: 80%;"><div style="background-color: #ffeeee;">Errors:</div>`+
                    _.chain(errors)
                        .map(e=>{
                            return `<div><b>${e.type}</b> ${e.value}</div>`;
                        })
                        .value()
                        .join('') +
                    `</div>`);
            }
        }
    });
});



This "infinite loop detected" error has become almost constant recently. I am having trouble getting the API to stay up for more than a few minutes.
It takes a long time for the API to work sometimes, such as when I start a new character. Then once it works, it works just fine, almost instantly. I think this lag causes all the commands to go through at once giving the impression of an infinite loop.
May 22 (9 years ago)

Edited May 22 (9 years ago)
I was changing about 100 attributes with a single command. I think that it was too much to handle in one macro. I changed things so I am only adjusting a dozen attributes and the error has not errored again so far.
Still seems to be an issue as of this morning, the first token I dropped to the map worked perfectly, without changing a thing and only a few seconds later the second one experianced the issue and I received the infinite loop message. 
May 26 (9 years ago)
Stephen Koontz
Forum Champion
Marketplace Creator
Sheet Author
API Scripter
Compendium Curator
Jason can you PM me the URL of your game and give me the name of the script that's causing you issues. I'll take a look.
I'm getting an infinite loop error as well, so I might as well post the offending script if it helps.
https://gist.github.com/GoCorral/9240004810d0667c5...
It's likely that the cause of my error is more conventional though. The script has a while loop containing a large if/else tree that can go on for a lot of iterations under certain conditions. How many times does something have to go through a while loop before the API shuts down the script?
June 20 (9 years ago)
Stephen Koontz
Forum Champion
Marketplace Creator
Sheet Author
API Scripter
Compendium Curator
If the API sandbox gets locked up for an extended period of time, it throws this error to free up your game if it's being hammered by a process that won't resolve. It also protects Roll20 from malicious intent. We designed this failsafe with even large processes, combing through a lot of your game's data, being returned well before it throws this error. So, if you're hitting it you may want to look at rethinking your approach.
Well, the script Blood and Honor, posted in these forums, seems to be triggering an infinite loop detection, but the script works fine otherwise. This seems to be a relatively new issue refer https://app.roll20.net/forum/post/3417461/help-blo...

Is the timeout value used to tripwire the infinite loop set to something low?  The script will work for awhile, then I have to go into the API and restart it to get it working again, its annoying. I completely understand needing something like this but wonder if the value used for 'timeout' or however you want to call it may be too strict.
July 05 (9 years ago)
Riley D.
Roll20 Team
When you guys are getting these infinite loop errors, are they happening right after you start the game (e.g. in the first 10 minutes), or are they happening after the game has been going for a long time?

The mechanism works by broadcasting a heartbeat from the client sandbox to the container once every 10 seconds. The container checks to make sure that it has heard a heartbeat at least once in the last 30 seconds, otherwise it assumes it's an infinite loop. So in theory you would need to tie up your process for a *long time* (like, 30+ seconds) before this should trigger. That said, I'm wondering if there might be an error with the way the detection is working.

Let me know under what circumstances you're seeing it and I'll look into it further.
July 05 (9 years ago)
Riley D.
Roll20 Team
Also, reviewing that thread, it "suddenly started" with that update because that's when we put the check in place (it wasn't there before). So it's possible there really is something wrong with that script, I wouldn't assume just because it wasn't triggering it before that it's well-behaved.
July 05 (9 years ago)
Riley D.
Roll20 Team
Actually give this version a try, I'm not sure if it will help but I made a few changes, including actually deleting the blood tokens when you do "!clearblood" instead of just hiding them in the upper-left corner, which could lead to a lot of unnecessary tokens clogging up your game. So I would do "!clearbood" after installing this new one to clear all those old blood tokens out if you weren't already deleting them manually.

https://gist.github.com/rileydutton/d01b80714df284...

July 06 (9 years ago)

Edited July 06 (9 years ago)

Riley D. said:

When you guys are getting these infinite loop errors, are they happening right after you start the game (e.g. in the first 10 minutes), or are they happening after the game has been going for a long time?

The mechanism works by broadcasting a heartbeat from the client sandbox to the container once every 10 seconds. The container checks to make sure that it has heard a heartbeat at least once in the last 30 seconds, otherwise it assumes it's an infinite loop. So in theory you would need to tie up your process for a *long time* (like, 30+ seconds) before this should trigger. That said, I'm wondering if there might be an error with the way the detection is working.

Let me know under what circumstances you're seeing it and I'll look into it further.

Hey Riley, I've had the issue happen when I first start the game up and when its been running for a while so it doesn't seem like that's having an effect on the issue one way or the other. I'll try out the script you linked, however mine seems to be related to a different script from what I can see. 

Edit: Same issue, I was able to drag two tokens to the table and had their HP rolled and set correctly, the third time I did it I ended up with the loop message.
July 07 (9 years ago)
Riley D.
Roll20 Team
Jason -- sorry, I was replying to Machine Ator's post. I had wondered if you were still having the issue since you hadn't posted in here for a month or so. Can you link me the full script you are using that is causing the issue and I'll take a look at it?

Riley D. said:

Jason -- sorry, I was replying to Machine Ator's post. I had wondered if you were still having the issue since you hadn't posted in here for a month or so. Can you link me the full script you are using that is causing the issue and I'll take a look at it?

Hey Riley,
No problem, here's the script that I'm working with. http://pastebin.com/raw/ziCgPnKX The issue seems to be around rolling random health for the token when its created. Or at least from the logging I've done that's where it gets stuck.
I have "one-click" installed group-init and when I start a game it often doesn't work. I check the API console and see "Possible infinite loop detected, shutting down."

After restarting the API sandbox things work again. 

Not sure if this is the same issue, but it's a minor nuisance.
From what I can see this continues to be an on going issue.