1

我不确定这是 Edgejs 的问题,我只是希望有人遇到同样的问题,并给出一些建议如何找出原因。无论如何,应该从.net运行时发生“由于StackOverflowException而终止的进程”,对吗?

图片

我的 Nodejs 代码是 tcp 服务器,每当收到数据时,它都会调用 .net 代码,而 .net 代码只负责将数据存储在 sql server 中。定义边缘功能的Nodejs代码如下:

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

});

以下是 updateStation 函数的 .net 代码:

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 从 Dll 的配置文件中读取,如下所示:

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

我只是使用实体框架来访问 sql server,而不是更复杂的代码。我很困惑,我查看了我的代码,没有找到任何递归调用。

关键是StachOverflowException在程序运行一段时间后发生,并不总是在同一个地方或同一时间发生,这对我来说很奇怪,看起来是随机的,但一段时间后总是发生异常,它是关于不超过 1 分钟。

4

0 回答 0