Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Stack overflow in ASPNet double edge brings down the process #114

Closed
andyrooger opened this issue Aug 30, 2020 · 1 comment · Fixed by #119
Closed

Stack overflow in ASPNet double edge brings down the process #114

andyrooger opened this issue Aug 30, 2020 · 1 comment · Fixed by #119

Comments

@andyrooger
Copy link
Contributor

andyrooger commented Aug 30, 2020

I'm running Edge.js in an ASPNet (not core) app running in IIS and a JS stack overflow causes the entire process to drop and my site goes down. More clearly:

try {
    var func = EdgeJs.Edge.Func("function x() { x(); }; x()");
    await func(null);
}
catch {
    Console.log("Error ignored (for this demonstration)");
}

If I run this in a standard exe, I see

Error ignored (for this demonstration)

If I do the same in IIS, the entire site immediately goes down.

Investigation

The reason is that running under IIS this causes a stack overflow in the main process rather than just node, and that can't be caught. In IIS the max stacksize is much smaller than a standard unmodified exe.

$ dumpbin.exe /headers my.exe | find "stack"
100000 size of stack reserve
1000 size of stack commit
$ dumpbin.exe /headers w3wp.exe | find "stack"
80000 size of stack reserve
2000 size of stack commit

Measurements are bytes in hex, so 1mb/4kb vs 512kb/8kb. I can patch my exe stack sizes to reproduce the terminal exception in a console app with

$ editbin /stack:524288,8192 EdgeJsStackOverflow.exe

so I'm happy this is the issue. (numbers are bytes in decimal)

Possible fix

The thread constructor takes a max stack size, so we can increase it for a single thread without patching the exe.

I've been using a fork of the tjanczuk edge.js for a year or two, patched to set the max stack size for the node thread to 1048576 (1mb) and it has worked well in 32 and 64 bit Windows systems on .Net Framework. I do not know what effect this would have for .Net Core or other platforms.

@agracio
Copy link
Owner

agracio commented Sep 5, 2020

Double edge is only supported on .NET Framework so you would not have any issues with other platforms.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants