while(true){}; causes intermittent hangs
vgarg opened this issue · comments
Hello,
I am using version 0.1.4 of the library and seeing intermittent hangs when using while(true){};
as the input javascript. Here is a test case that reproduces the problem:
@Test
public void testIsMatchCpuAbuseDirect() {
String js = "while (true) {};";
for (int i = 0; i < 1000; i++) {
System.out.println("i = " + i);
NashornSandbox sandbox = NashornSandboxes.create();
sandbox.setMaxCPUTime(100); // in millis
sandbox.setMaxMemory(1000 * 1000); // 1 MB
sandbox.allowNoBraces(false);
sandbox.setMaxPerparedStatements(30); // because preparing scripts for execution is expensive
sandbox.setExecutor(Executors.newSingleThreadExecutor());
Exception exp = null;
try {
Object result = sandbox.eval(js);
} catch (Exception e) {
exp = e;
}
Assert.assertNotNull(exp);
}
}
Also worth noting that the test case completes with successfully if the script is changed to: var o={}, i=0; while (true) {o[i++]='a';};
Would appreciate any help on the issue.
Thank you for reporting this issue. There was a bug in the CPU monitor class. This is fixed now and included in version 0.1.6 which should be available in Maven central presently.
Does this solve your issue?
Thanks @mxro for the quick turnaround on this. I will give this a try Today and report back.
The fix worked. Thanks Much!!!
Thank you for testing it! I will close the issue now!