edge icon indicating copy to clipboard operation
edge copied to clipboard

Unresolved JavaScript Promises can terminate the CLR hosting process

Open moodmosaic opened this issue 8 years ago • 1 comments

If some bad JavaScript code (e.g. unresolved Promises) gets executed, there's a NullReferenceException being thrown from the Edge.NodeStart call, and that exception doesn't seem to be able to get caught:

e.ExceptionObject
{"Object reference not set to an instance of an object."}
    Data: {System.Collections.ListDictionaryInternal}
    HResult: -2147467261
    HelpLink: null
    InnerException: null
    Message: "Object reference not set to an instance of an object."
    Source: "edge"
    StackTrace: "
        at NodejsFuncInvokeContext.CompleteWithError(Exception exception)\r\n
        at NodejsFuncInvokeContext.CompleteWithResult(Handle<v8::Value> result)\r\n
        at v8FuncCallback(Handle<v8::Value>* , Arguments* args)"
    TargetSite: {Void CompleteWithError(System.Exception)}

This brings down the whole CLR process (e.g. IIS) which is really unacceptable. Even if I put a try-catch block around the code that calls into Edge, or around the Edge.NodeStart call the process still terminates.


In terms of pseudo-code, something like this causes Edge to throw the above exception, and the whole CLR process and IIS are terminated!

e.sendEmail().then(function(result) {
    e.returnValue = result;
   // No callback, that's on purpose.
});
// Instead, do the callback here, which
// means when the promise completes the 
// callback has already being called.
callback(null, {});

moodmosaic avatar Mar 19 '16 06:03 moodmosaic