Possible to set a timeout?

Aug 5, 2011 at 4:56 PM

I'm planning to use Jurassic in a game for modding purposes. What I want to avoid is players greifing and crashing the server by typing "while (true) { }" or something similar. Is there a way to set a timeout where code throws an exception after running too long? I'd put the limit at something like 3 seconds... there's absolutely no reason for user-defined code to run that long.

Aug 6, 2011 at 4:07 AM

There's no way built into Jurassic, but it's not hard to spawn a thread, run the user-defined code in the thread while waiting for it to exit in the parent thread (using Thread.Join).  If Thread.Join times out you can abort the thread using Thread.Abort.

However, there are some limitations:
a) You can't protect against stack overflow exceptions - not even if you spawn a new appdomain to run the code.
b) You can't really protect against the code allocating tons of RAM (you might be able to do this using AppDomains, not sure).