VMware Cloud Community
Czernobog
Expert
Expert
Jump to solution

vRO 6.0 - max number of loop iterations before script fails

I've built a small workflow that iterates through an xml object and converts part of it into a string which will become a simple html file. The iteration is done by using a for loop.

The workflow stops during execution and the scriptable task is highlighted red, but no exception is thrown.

I've checked the server.log for details and there I have found:

4-cde3-4e09-bd44-14b5f7106c61]} [WorkflowHandler] Error in execution of workflow 'WFNAME for wfExecution[8abe988e569502d9015698f065810146]

java.lang.StackOverflowError

    at org.mozilla.javascript.ConsString.appendFragment(ConsString.java:78)
    at org.mozilla.javascript.ConsString.appendTo(ConsString.java:73)
    at org.mozilla.javascript.ConsString.appendFragment(ConsString.java:79)
    at org.mozilla.javascript.ConsString.appendTo(ConsString.java:73)

(...)

    at org.mozilla.javascript.ConsString.appendFragment(ConsString.java:79)
    at org.mozilla.javascript.ConsString.appendTo(ConsString.java:73)

2016-08-17 16:38:26.993+0200 [WorkflowExecutorPool-Thread-40] DEBUG {USERNAME:WFNAME:8abe988e569502d9015698f065810146:f97a79c4-cde3-4e09-bd44-14b5f7106c61:[f97a79c4-cde3-4e09-bd44-14b5f7106c61]} [WorkflowHandler] Ending WorkflowHandler (8abe988e569502d9015698f065810146), with status[failed]

2016-08-17 16:38:26.996+0200 [WorkflowExecutorPool-Thread-40] DEBUG {USERNAME:WFNAME:8abe988e569502d9015698f065810146:f97a79c4-cde3-4e09-bd44-14b5f7106c61:[f97a79c4-cde3-4e09-bd44-14b5f7106c61]} [WorkflowHandler] Disconnect factory for WorkflowHandler (8abe988e569502d9015698f065810146), with clean session[true]

2016-08-17 16:38:26.996+0200 [WorkflowExecutorPool-Thread-40] DEBUG {USERNAME:WFNAME:8abe988e569502d9015698f065810146:f97a79c4-cde3-4e09-bd44-14b5f7106c61:[f97a79c4-cde3-4e09-bd44-14b5f7106c61]} [VSOFactoryClient] Disconnect from server

2016-08-17 16:38:27.006+0200 [WorkflowExecutorPool-Thread-40] DEBUG {USERNAME:WFNAME:8abe988e569502d9015698f065810146:f97a79c4-cde3-4e09-bd44-14b5f7106c61:[f97a79c4-cde3-4e09-bd44-14b5f7106c61]} [WorkflowHandler] MainScriptingObject exited

2016-08-17 16:38:27.007+0200 [WorkflowExecutorPool-Thread-40] DEBUG {USERNAME:WFNAME:8abe988e569502d9015698f065810146:f97a79c4-cde3-4e09-bd44-14b5f7106c61:[f97a79c4-cde3-4e09-bd44-14b5f7106c61]} [DynamicFunctionCaching] --contextReleased

2016-08-17 16:38:27.008+0200 [WorkflowExecutorPool-Thread-40] DEBUG {USERNAME:WFNAME:8abe988e569502d9015698f065810146:f97a79c4-cde3-4e09-bd44-14b5f7106c61:[f97a79c4-cde3-4e09-bd44-14b5f7106c61]} [WorkflowHandler] Context exited

First I thought that the max string length was reached, however after checking the string length this was not an issue. After that I have thought that maybe a limit of loop iterations was reached and that seems to be the cause. I've built a small workflow that would test my theory and there I have reached the maximum of 2000 loop iteration before the error mentioned above was reported again. This is true for the total number of loop iterations in the scriptable task, so you can have multiple for loop executed one after the other, the total number of iterations cannot exceed 2000.

The question is of course - is it possible to raise the limit?

Tags (1)
Reply
0 Kudos
1 Solution

Accepted Solutions
iiliev
VMware Employee
VMware Employee
Jump to solution

Hi,

I'm not aware of such loop iteration limitation. Could you send me the test workflow you use to reproduce this stack overflow exception?

BTW, looking at the stack trace, it seems that the issue could be related to concatenation of large number of ConsString objects. In Rhino 1.7R4, when you concatenate two strings, the result will be of type ConsString instead of normal string. Here is some sample code:

var x = "some string"; 

var y = "another string"; 

var z = x + y; // this is of type ConsString in Rhino 1.7R4; used to be string in Rhino 1.7R3 

func(z); // the function will receive an object of type ConsString

func(z.valueOf()); // the function will receive an object of type string

So, if you are doing a lot of string concatenations in your script code, you may consider 'flattening' the results of concatenation (eg. by using valueOf()). I'm not sure if this will prevent stack overflow error, but I think it is worth to try.

View solution in original post

Reply
0 Kudos
2 Replies
iiliev
VMware Employee
VMware Employee
Jump to solution

Hi,

I'm not aware of such loop iteration limitation. Could you send me the test workflow you use to reproduce this stack overflow exception?

BTW, looking at the stack trace, it seems that the issue could be related to concatenation of large number of ConsString objects. In Rhino 1.7R4, when you concatenate two strings, the result will be of type ConsString instead of normal string. Here is some sample code:

var x = "some string"; 

var y = "another string"; 

var z = x + y; // this is of type ConsString in Rhino 1.7R4; used to be string in Rhino 1.7R3 

func(z); // the function will receive an object of type ConsString

func(z.valueOf()); // the function will receive an object of type string

So, if you are doing a lot of string concatenations in your script code, you may consider 'flattening' the results of concatenation (eg. by using valueOf()). I'm not sure if this will prevent stack overflow error, but I think it is worth to try.

Reply
0 Kudos
Czernobog
Expert
Expert
Jump to solution

Thanks for looking into it. As you have mentioned, my script does a lot of script concatenation.

I wanted to test your method today and before that I have ran my workflow again. To my suprise, this time it has finished without errors! After I have faced the issue for the first time, I've increased the sizing of the vRO appliance from standard values to 4 CPUs + 8GB RAM and also increased the JVM heap to 6144MB, just to see if that would change something. This measure has not helped however so I made the community post but today it seemed to work for the first time. To check if this is dependent on the JVM heap sizing, I have reduced it to 2048MB, tested and got the same error. After increasing the heap size to 6144MB I got the error again.

At this point I have tried your solution and it does seem to work! Every time the "top level" loop runs, I convert the string object to the primitive value with

output = output.valueOf();

EDIT: After successfully testing your solution with my main workflow I ran a small test workflow again:

for (var i = 0; i < 5000; i++){ text += "T"; System.log(text.length) }

It ran past 2000 iterations without the .valueOf(); conversion!

I went back to my original workflow and removed the .valueOf(); method and the workflow finished without errors too.

So, I don't really know what is happening, but I will leave the .valueOf(); part in my main workflow, just to be sure the workflow runs every time.

Reply
0 Kudos