我们有一个 NodeJS 应用程序在基于 Linux 的应用程序服务计划上作为 Azure Web 应用程序服务运行。(配置为像往常一样运行)。
设置:
- 节点JS 16
- 应用服务计划 (Linux)
- Redis(Azure 托管托管服务)
- Application Insights(Azure 托管托管服务)
套餐:
- 表达 4.17.2
- dotenv 14.2.0
- redis 4.0.2
- 应用洞察 2.2.0
Web 服务执行基本数据计算,并将结果作为 REST API 服务返回。Redis 用于存储之前计算的结果。
Application Insights 已在门户中的应用服务级别启用。对于额外的故障监控,我们在代码中添加了 NPM 包applicationinsights版本 2.2.0。
应用程序洞察力在应用程序启动时使用:
const appInsights = require("applicationinsights");
appInsights.setup(process.env.APPLICATIONINSIGHTS_CONNECTION_STRING)
appInsights.start()
应用服务运行了一段时间,但随后在 KUDU 日志中出现以下意外崩溃:
2022-01-20T00:41:19.028838008Z events.js:377
2022-01-20T00:41:19.029056811Z throw er; // Unhandled 'error' event
2022-01-20T00:41:19.029073211Z ^
2022-01-20T00:41:19.029079111Z
2022-01-20T00:41:19.029084211Z SocketClosedUnexpectedlyError: Socket closed unexpectedly
2022-01-20T00:41:19.029089512Z at TLSSocket.<anonymous> (/home/site/wwwroot/node_modules/@node-redis/client/dist/lib/client/socket.js:184:118)
2022-01-20T00:41:19.029095412Z at Object.onceWrapper (events.js:520:26)
2022-01-20T00:41:19.029100512Z at TLSSocket.emit (events.js:412:35)
2022-01-20T00:41:19.029105412Z at net.js:675:12
2022-01-20T00:41:19.029110212Z at TCP.done (_tls_wrap.js:563:7)
2022-01-20T00:41:19.029115112Z Emitted 'error' event on Commander instance at:
2022-01-20T00:41:19.029128012Z at RedisSocket.<anonymous> (/home/site/wwwroot/node_modules/@node-redis/client/dist/lib/client/index.js:338:14)
2022-01-20T00:41:19.029149012Z at RedisSocket.emit (events.js:400:28)
2022-01-20T00:41:19.029154512Z at RedisSocket._RedisSocket_onSocketError (/home/site/wwwroot/node_modules/@node-redis/client/dist/lib/client/socket.js:207:10)
2022-01-20T00:41:19.029159212Z at TLSSocket.<anonymous> (/home/site/wwwroot/node_modules/@node-redis/client/dist/lib/client/socket.js:184:107)
2022-01-20T00:41:19.029164013Z at Object.onceWrapper (events.js:520:26)
2022-01-20T00:41:19.029168413Z [... lines matching original stack trace ...]
2022-01-20T00:41:19.029172813Z at TCP.done (_tls_wrap.js:563:7)
然后我取消了使用 Redis 来测试没有外部连接的场景,但是运行一段时间后,应用程序仍然崩溃而没有触发 try/catch 代码。
我能够跟踪以下调试信息:
arg0:OperationalError {cause: Error: read ECONNRESET
at TCP.onStreamRead…nternal/stream_base_commons:220:20)
at TC…, isOperational: true, errno: -4077, code: 'ECONNRESET', syscall: 'read', …}
cause:Error: read ECONNRESET\n at TCP.onStreamRead (node:internal/stream_base_commons:220:20)\n at TCP.callbackTrampoline (node:internal/async_hooks:130:17) {errno: -4077, code: 'ECONNRESET', syscall: 'read', stack: 'Error: read ECONNRESET\n at TCP.onStreamRea…Trampoline (node:internal/async_hooks:130:17)', message: 'read ECONNRESET'}
code:'ECONNRESET'
errno:-4077
isOperational:true
syscall:'read'
message:'read ECONNRESET'
name:'Error'
stack:'Error: read ECONNRESET\n at TCP.onStreamRead (node:internal/stream_base_commons:220:20)\n at TCP.callbackTrampoline (node:internal/async_hooks:130:17)'
我的本地调试控制台将我指向文件:/ node_modules\diagnostic-channel-publishers\dist\src\console.pub.js :43:39 ,据我了解,该文件用于将控制台日志事件记录到 Application Insights*。
然后我删除了 Application Insights,Web 应用程序一直在稳定运行,没有任何崩溃。我重新启用了 Redis 的使用,到目前为止没有发现任何问题。这指出我的问题是 Application Insights 无法正常处理与 Application Insights 服务的 TCP 套接字连接中断。
有什么方法可以确认这一点或防止应用程序崩溃?