-
Notifications
You must be signed in to change notification settings - Fork 83
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Failed to restrict the cpu and memory utilization for few scenarios #34
Comments
Hi Srinivas, Thank you for exploring different scenarios and reporting this issue. I've created a test case for all the scenarios that you have listed. I don't see how the CPU/Memory limit would not work for these? They are all scripts that don't go into an infinite loop or do otherwise resource intensive operations. Please confirm that my tests reflect the scenarios correctly! I see that the syntax in some of the tests is not quite 'clean'. Please note that assuring that user scripts are provided in 'pretty' and 'clean' JS syntax is out of scope for this library. Its purpose is to create a sandbox for JS in Nashorn. |
Hi Maxro, I agree, for scenario 1, 2, 3. As we are using thread monitoring and if the thread is not terminated after some time, we are forcefully stop the thread by making call as threadToMonitor.stop(); (which is deprecated in java now). But for scenario 4 //simple do-while loop for demo Assuming below is my test java code to run the script the above script fails with the below exception. As I have do-while loop for demo in javascript comment it is assuming that the for as keyword and throwing exception as there is no braces. I think this is some thing can be fixed by proper pattern matching. java.lang.Exception: Unexpected exception, expected<delight.nashornsandbox.exceptions.ScriptCPUAbuseException> but was<delight.nashornsandbox.exceptions.BracesException> |
Hi Srinivas, I've added the scenario you describe in the test case under testIssue34_Scenario5 in TestIssue34.java. I don't get a BracesException when running this. Only the ScriptCPUException. So all seems fine to me. Please check out my test case locally and compare it to your code. Please provide me with a full example I can execute myself if things don't work as you expect! Max |
Hi Maxro, This is the updated test cases is failing. Please check @test
|
Hi Srinivas, Thank you for further testing this. Firstly, the code you have submitted misses a '\n' at the end of this line:
Should be:
I have fixed that and added this test case as It looks like the braces exception was triggered by the 'do' included in the first name comment. I have patched the library now so that it will ignore all code in comments in checking for braces. Please note that the updated code is not yet uploaded to Maven central. Let me know if there is anything else you find. |
No other issues, please merge fixes |
Version 0.1.8 is released to Maven Central and should be available there shortly. Let us know if you have any further issues. |
I'd like to get more information on this for #52. The tests do not contain any descriptions, and they look like they should either be a different type of test, or injected into the existing scenarios. |
Hi,
We have identified few scenarios where this library is failing to control the usage.
// Scenario 1:
function main(){
for(var i=0;i<2;i++)
logger.debug("loop cnt-"+i);
}
function main2(){
}
main();
//Scenario 2:
function main(){
logger.debug("... In fun1()....");
for(var i=0;i<2;i++)//{
logger.debug("loop cnt-"+i);
}
main();
//Scenario 3:
//simple do-while loop for demo
function loopTest(){
var i=0;
do{
logger.debug("loop cnt="+(++i));
}while(i<11)
}
loopTest();
//Scenario 4:
if(srctable.length) srctable.length = 0;__if();
else {
for(var key in srctable) {__if();
delete srctable[key];
}
}
All the above scenarios can be easily addressed if apply JSLint/JSHint/ESLint kind of JS libraries. Can you please check any other possibilities here.
The text was updated successfully, but these errors were encountered: