Force a global reset
-
const heap_bomb = () => { new Uint32Array(8*1024*1024); heap_bomb(); }; heap_bomb();
I've tried this code -- works fine, but takes 2 ticks to reset global. As I see, for now the only way to force global reset is "heap overflow" or critical error, but one does not simply throw a critical error from sandbox
UPD: well, nope, it takes ~10 ticks, jeez (at least on PTR):
[3:38:10 PM][shard0]GAME TIME 24980814 const heap_bomb = () => { new Uint32Array(8*1024*1024); heap_bomb(); }; heap_bomb(); [3:38:25 PM][shard0]Script execution timed out ungracefully [3:38:32 PM][shard0]Script execution timed out ungracefully, restarting virtual machine [3:38:35 PM][shard0]GAME TIME 24980823
-
A code push also triggers a new reset iirc.
-
@joykill, you cannot push code from you code, obviously) See the topic issue:
Is there a way to force a global reset from within the game loop with the iVM architecture?
-
So after trying a few ways, I created a module that requires itself. I include that conditionally at the end of the loop, and then I can trigger it by conditionally requiring the module without burning CPU or losing a tick.
Not exactly elegant, but it works.
-
@black0441 does
Memory
get saved for you or are you losing it on the ticks where you trigger this? Are you getting an error when you call this?
-
Memory is not affected, it's the same thing as a syntax error in a code download.
-
@mototroller said in Force a global reset:
const heap_bomb = () => { new Uint32Array(810241024); heap_bomb(); };
This works in console, but doesn't seem to work in code.
I'm going to test black's solution. Seems like it should work more reliably.
-
@tigga Are you using TS or some sort of code optimiser? This is not work for me because TS is remove allocation of memory when compiling because this variable is never use.
-
No, the code runs, it just causes my script to timeout rather than blowing out the heap and triggering a reset.
-
A syntax error doesn't work, nor did the circular require.
Still have no way to do this from code AFAIK.
-
How about this?
let reset = false
exports.forceReset() = function() { reset = true }
module.__initGlobals = function() { if (!reset ) return reset = false throw new Error("boom") }
This will throw an exception outside of the regular evalCode wrapper. I think this will make the vm think it threw the exception and reset the global.