tripwire icon indicating copy to clipboard operation
tripwire copied to clipboard

recover from tripwire firing

Open jacksonloper opened this issue 8 years ago • 3 comments

After the tripwire fires, my script exits, whether I call process.exit(1) or not.

For example, this code...

var tripwire = require("tripwire");

process.on('uncaughtException', function (e) {
   console.log('Doom');
});

tripwire.resetTripwire(2000);

console.log("Hello")
try { 
    while(true) {}
} catch(err) {
    console.log("Goodbye");
}

... prints "Hello" and "Doom" but not "Goodbye"

I suppose there's no way around this. It's presumably sort of the same problem as #1.

jacksonloper avatar Nov 03 '15 17:11 jacksonloper

This is the nature of uncaughtException - tripwire can't cause the while statement to throw an error so you never get to your catch block.

rpaterson avatar Dec 16 '15 23:12 rpaterson

So I would not expect the original code block to continue, but what exactly happens internally? It appears that the code/callback that caused the block has stopped, but is there no way to continue flush the event loop and continue with the process?

I added a callback in my context so that uncaughtException executes the callback in my game:

who Kriton the newbie

eval while(true);

*boom uncaughtException fires, I try and clear/reset tripWire and exec the callback which prints:

Command exceeded max execution time. <-- This was printed after the uncaught handler.

But now I am stuck in a loop where tripwire is firing an exception every 2000ms and I can't seem to clear or reset it. Here is what I am trying:


            process.on('uncaughtException', err => {
                let ctx = tripwire.getContext();
                if (ctx) {
                    ctx.callback(ctx.input);
                    setImmediate(() => {
                        tripwire.clearTripwire();
                    });
                }
                logger.log(err);
                logger.log(err.stack);
                this.errorHandler(err, false);
            });


kristianoye avatar Jan 14 '18 05:01 kristianoye

I see V8 has a "CancelTerminateExecution()" that seems like it should be able to resume the original isolate/script once the event loop is all cleared out. My C++ is super rusty, though. I have created a fork of this project to try and get a working proof-of-concept.

kristianoye avatar Jan 15 '18 06:01 kristianoye