Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

StackOverFlowException thrown and process terminated #253

Closed
leoyoo opened this issue Mar 15, 2015 · 10 comments
Closed

StackOverFlowException thrown and process terminated #253

leoyoo opened this issue Mar 15, 2015 · 10 comments

Comments

@leoyoo
Copy link

leoyoo commented Mar 15, 2015

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
Copy link
Author

leoyoo commented Mar 15, 2015

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
Copy link
Author

leoyoo commented Mar 24, 2015

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

@Earl-Brown
Copy link

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
Copy link

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!

@QueueHammer
Copy link

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"
    }
  }
}

@jijiechen
Copy link

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.

@agracio
Copy link
Collaborator

agracio commented Oct 20, 2017

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

@vpradeepkumar94
Copy link

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.

@agracio
Copy link
Collaborator

agracio commented Oct 20, 2017

As per my previous comment, #566 addresses StackOverflow issue but was not merged to the repo. Use edge-js module instead.

@mattspeller
Copy link

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.

@agracio agracio closed this as completed Sep 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants