edge icon indicating copy to clipboard operation
edge copied to clipboard

StackOverFlowException thrown and process terminated

Open leoyoo opened this issue 9 years ago • 10 comments

I'm not sure this is the issue from Edgejs, I just hope anyone meet the same issue with this, and give some suggestions how to figure out the reason. anyway, 'process is terminated due to StackOverflowException' should be happened from .net runtime, right?
image

My Nodejs codes are tcp server, whenever data received, it will call the .net code and the .net code is just responsible for storing data in sql server. Nodejs code which define the edge function as below:

module.exports.updateStation = edge.func({
    assemblyFile: clrAssembly,
    typeName: clrType,
    methodName: 'UpdateStationAsync'
});

below is the .net code for the updateStation function:

public async Task<object> UpdateStationAsync(dynamic station)
    {
        string projid = (string)station.projid;
        string stid = (string)station.stid;
        using (var context = new FlyDataContext(ConnectString))
        {
            var st = await context.Stations.FirstOrDefaultAsync(
                s => s.ProjectID == projid && s.StationID == stid);
            if (st != null)
            {
                st.IpAddress = (string)station.ip;
                st.IpPort = (int)station.port;
                st.ServerPort = (int)station.serverport;
                st.LastCmd = (string)station.cmd;
                st.LastUpdated = DateTime.Now;
            }
            else
            {
                st = new Station()
                {
                    ProjectID = projid,
                    StationID = stid,
                    IpAddress = (string)station.ip,
                    IpPort = (int)station.port,
                    ServerPort = (int)station.serverport,
                    Interval = 10,
                    LastCmd = (string)station.cmd,
                    LastUpdated = DateTime.Now
                };
                context.Stations.Add(st);
            }

            return await context.SaveChangesAsync();
        }
    }

ConnectString is read from config file of the Dll, like below:

    private static string _connString = null;
    protected static string ConnectString
    {
        get
        {
            if (string.IsNullOrEmpty(_connString))
            {
                string codeBase = Assembly.GetExecutingAssembly().CodeBase;
                UriBuilder uri = new UriBuilder(codeBase);
                string path = Uri.UnescapeDataString(uri.Path);
                string configpath = Path.Combine(Path.GetDirectoryName(path), "Fly.Data.dll.config");
                XDocument doc = XDocument.Load(configpath);
                XElement root = doc.Root;
                _connString = (from e in root.Element("connectionStrings").Elements("add")
                               where e.Attribute("name").Value == "FlyDataContext"
                               select e.Attribute("connectionString").Value).FirstOrDefault();
            }
            return _connString;
        }
    }

I just use Entity Framework to access sql server, not more complex codes there. I'm confused that I looked through my codes, didn't find any recursion calling.

And the point is StachOverflowException happens after the program running for a while, not always occurred at the same place or same time, it 's so strange to me, looks like it is random, but exception always happen after a while, it is about no more than 1 minute.

leoyoo avatar Mar 15 '15 04:03 leoyoo

I wan to know what the thread model like when Edgejs calling .net codes at run time. when edge call a function, it will create one instance of that .net type and call the method of that instance? and is this call working on a separated thread? then if concurrent calls happens, will multiple managed threads working in .NET CLR?

leoyoo avatar Mar 15 '15 04:03 leoyoo

nobody else met this kind of issue? why no any response or I posted in wrong place?

leoyoo avatar Mar 24 '15 01:03 leoyoo

I am having a similar issue when using edge-sql. I've been able to debug inside of the edge-sql C# code, and the StackOverflowException is happening from inside the edge compiled code (nativeclr or native_clr namespace, but that's all I can figure out).

It's easy to trigger with edge-sql. Simply try to run an SQL command with a connection string that fails authentication.

Earl-Brown avatar Apr 15 '16 17:04 Earl-Brown

I rewrote my SQL access to be via a DLL, and still have the StackOverflowException happening when I attempt "Connection.Open" using invalid authentication details. So my issue is not something introduced by edge-sql.

I hope this makes it easy for the developers to identify and resolve the problem!

Earl-Brown avatar Apr 20 '16 17:04 Earl-Brown

I have the the same issue when trying to setup a basic example of pulling in a dll.

Process is terminated due to StackOverflowException.
Abort trap: 6

Here is the reference code Calling file:

var pathToDll = `${__dirname}/dll/bin/Debug/netcoreapp1.1/dll.dll`;
var helloWorld3 = edge.func(pathToDll);
helloWorld3('JavaScript3', function (error, result) {
    if (error) throw error;
    console.log(result);
});

Compiled Code:

using System;
using System.Threading.Tasks;

namespace My.Edge.Samples
{
    public class Startup
    {
        public async Task<object> Invoke(object input)
        {
            return $".Net Welcomes {input.ToString()}";
        }
    }
}

Project.json:

{
  "version": "1.0.0-*",
  "buildOptions": {
    "debugType": "portable",
    "emitEntryPoint": false
  },
  "dependencies": {},
  "frameworks": {
    "netcoreapp1.1": {
      "dependencies": {
        "Microsoft.NETCore.App": {
          "type": "platform",
          "version": "1.1.0"
        }
      },
      "imports": "dnxcore50"
    }
  }
}

QueueHammer avatar Feb 10 '17 04:02 QueueHammer

Just for others who is running into similar problems, to address the issues of "terminated with stack overflow":

just add an environment variable EDGE_DEBUG, and set its value to 1 before executing your app

you'll see the full trace and debug information on initializing edge and invoking your assembly.

jijiechen avatar Oct 20 '17 04:10 jijiechen

I have created PR to fix it https://github.com/tjanczuk/edge/pull/566, but it never got merged. My fork https://github.com/agracio/edge-js supports it.

agracio avatar Oct 20 '17 07:10 agracio

Hi, Even I have got stuck with the same issue,when trying to connect to database using Edge - SQL from Protractor. I have attached the screenshot of the stack trace which I got after adding the environmental variable stacktrace.

Kindly let me know,is there any other work around for this, As this is blocking me from proceeding with my automation script.

vpradeepkumar94 avatar Oct 20 '17 08:10 vpradeepkumar94

As per my previous comment, https://github.com/tjanczuk/edge/pull/566 addresses StackOverflow issue but was not merged to the repo. Use edge-js module instead.

agracio avatar Oct 20 '17 10:10 agracio

For a pointer for others in my case I had a cyclical object reference in my object and this caused issues marshalling across the boundaries. I removed my property and everything worked as expected.

mattspeller avatar Jun 12 '18 13:06 mattspeller