1

后端设置:

  • 在端口 5000 上运行的 Node.js/Express 服务器
  • AWS S3(用于图像)
  • AWS RDS Mysql(用于数据)

嗨,大家好,

我是前端的人,所以我对后端不太了解,我刚开始学习。

我在端口 5000 上有一个 Node.js/Express 服务器,用于连接到 S3 存储桶和 RDS Mysql 数据库,这对于我目前正在开发的 React 前端来说已经足够了。

我使用 nodemon 来处理断开连接并自动重新连接。它过去 24/7 都可以正常工作,但在过去的 3 个月里我一定改变了一些东西,现在它每天崩溃几次,我必须手动重新启动服务器。这不是什么大问题,但我想学习如何处理它。

这是我不断收到的错误:

[nodemon] restarting due to changes...
[nodemon] starting `node server.js`
Listening on port 5000..
Connection Established Successfully
Error: read ECONNRESET
    at TCP.onStreamRead (internal/stream_base_commons.js:205:27)
    --------------------
    at Protocol._enqueue (/Volumes/Content/Desktop/Dropbox/HugoPrivate/React/ladswork-server/node_modules/mysql/lib/protocol/Protocol.js:144:48)
    at Connection.query (/Volumes/Content/Desktop/Dropbox/HugoPrivate/React/ladswork-server/node_modules/mysql/lib/Connection.js:198:25)
    at /Volumes/Content/Desktop/Dropbox/HugoPrivate/React/ladswork-server/routes/meProfileImageData.js:10:12
    at Layer.handle [as handle_request] (/Volumes/Content/Desktop/Dropbox/HugoPrivate/React/ladswork-server/node_modules/express/lib/router/layer.js:95:5)
    at next (/Volumes/Content/Desktop/Dropbox/HugoPrivate/React/ladswork-server/node_modules/express/lib/router/route.js:137:13)
    at Route.dispatch (/Volumes/Content/Desktop/Dropbox/HugoPrivate/React/ladswork-server/node_modules/express/lib/router/route.js:112:3)
    at Layer.handle [as handle_request] (/Volumes/Content/Desktop/Dropbox/HugoPrivate/React/ladswork-server/node_modules/express/lib/router/layer.js:95:5)
    at /Volumes/Content/Desktop/Dropbox/HugoPrivate/React/ladswork-server/node_modules/express/lib/router/index.js:281:22
    at Function.process_params (/Volumes/Content/Desktop/Dropbox/HugoPrivate/React/ladswork-server/node_modules/express/lib/router/index.js:335:12)
    at next (/Volumes/Content/Desktop/Dropbox/HugoPrivate/React/ladswork-server/node_modules/express/lib/router/index.js:275:10) {
  errno: 'ECONNRESET',
  code: 'ECONNRESET',
  syscall: 'read',
  fatal: true
}
Error: Cannot enqueue Query after fatal error.
    at Protocol._validateEnqueue (/Volumes/Content/Desktop/Dropbox/HugoPrivate/React/ladswork-server/node_modules/mysql/lib/protocol/Protocol.js:212:16)
    at Protocol._enqueue (/Volumes/Content/Desktop/Dropbox/HugoPrivate/React/ladswork-server/node_modules/mysql/lib/protocol/Protocol.js:138:13)
    at Connection.query (/Volumes/Content/Desktop/Dropbox/HugoPrivate/React/ladswork-server/node_modules/mysql/lib/Connection.js:198:25)
    at /Volumes/Content/Desktop/Dropbox/HugoPrivate/React/ladswork-server/routes/meProfileImageData.js:10:12
    at Layer.handle [as handle_request] (/Volumes/Content/Desktop/Dropbox/HugoPrivate/React/ladswork-server/node_modules/express/lib/router/layer.js:95:5)
    at next (/Volumes/Content/Desktop/Dropbox/HugoPrivate/React/ladswork-server/node_modules/express/lib/router/route.js:137:13)
    at Route.dispatch (/Volumes/Content/Desktop/Dropbox/HugoPrivate/React/ladswork-server/node_modules/express/lib/router/route.js:112:3)
    at Layer.handle [as handle_request] (/Volumes/Content/Desktop/Dropbox/HugoPrivate/React/ladswork-server/node_modules/express/lib/router/layer.js:95:5)
    at /Volumes/Content/Desktop/Dropbox/HugoPrivate/React/ladswork-server/node_modules/express/lib/router/index.js:281:22
    at Function.process_params (/Volumes/Content/Desktop/Dropbox/HugoPrivate/React/ladswork-server/node_modules/express/lib/router/index.js:335:12) {
  code: 'PROTOCOL_ENQUEUE_AFTER_FATAL_ERROR',
  fatal: false
}

显然,当我在不知道服务器已经崩溃的情况下尝试连接时,就会发生第二部分。

stackoverflow 上有很多关于类似 ECONNRESET 问题的帖子,所以很可能我的确切问题已经在其他地方得到了答复,但老实说,我在这方面还不够好,还不能自己吸收答案,我可以使用一些指针来说明问题似乎在哪些文件中或您可以告诉我的任何内容。

我在几篇文章中看到处理此类问题的最佳方法是设置错误侦听器,我很乐意这样做,但老实说我不知道​​从哪里开始,因为问题发生在什么时候我通常不使用服务器,比如在晚上或什至不在电脑前的时候。我不知道如何自己重现这个问题,只要它发生,它就会自行发生,所以这就是为什么我很难知道从哪里开始。我查看了我的 S3 和 RDS Mysql 上的日志,没有看到任何似乎与此直接相关的内容。

你能根据你在这里看到的内容给我一些建议吗?我有一些可能的想法:

  • 可能是 index.js 上的路由器导致了这种情况吗?
  • 当我查看我的 RDS Mysql 数据库面板时,我看到目前有 3 个活动连接,即使我在 2 小时前停止工作。会不会是那些连接超时导致了这种情况?(在另一篇文章中阅读)
  • 可能是 meProfileImageData.js 应该首先得到错误侦听吗?

这就是我现在所拥有的,任何想法或建议都非常受欢迎,如果您愿意花时间帮助我,我很乐意运行任何测试或安装任何必要的附加软件来解决此问题。

谢谢


编辑 1:今天有一个新错误,似乎指向连接被自动关闭,并且 Node.js 在尝试连接之前没有处理它:

Error: read ETIMEDOUT
    at TCP.onStreamRead (internal/stream_base_commons.js:205:27)
    --------------------
    at Protocol._enqueue (/Volumes/Content/Desktop/Dropbox/HugoPrivate/React/ladswork-server/node_modules/mysql/lib/protocol/Protocol.js:144:48)
    at Connection.query (/Volumes/Content/Desktop/Dropbox/HugoPrivate/React/ladswork-server/node_modules/mysql/lib/Connection.js:198:25)
    at /Volumes/Content/Desktop/Dropbox/HugoPrivate/React/ladswork-server/routes/meProfileImageData.js:10:12
    at Layer.handle [as handle_request] (/Volumes/Content/Desktop/Dropbox/HugoPrivate/React/ladswork-server/node_modules/express/lib/router/layer.js:95:5)
    at next (/Volumes/Content/Desktop/Dropbox/HugoPrivate/React/ladswork-server/node_modules/express/lib/router/route.js:137:13)
    at Route.dispatch (/Volumes/Content/Desktop/Dropbox/HugoPrivate/React/ladswork-server/node_modules/express/lib/router/route.js:112:3)
    at Layer.handle [as handle_request] (/Volumes/Content/Desktop/Dropbox/HugoPrivate/React/ladswork-server/node_modules/express/lib/router/layer.js:95:5)
    at /Volumes/Content/Desktop/Dropbox/HugoPrivate/React/ladswork-server/node_modules/express/lib/router/index.js:281:22
    at Function.process_params (/Volumes/Content/Desktop/Dropbox/HugoPrivate/React/ladswork-server/node_modules/express/lib/router/index.js:335:12)
    at next (/Volumes/Content/Desktop/Dropbox/HugoPrivate/React/ladswork-server/node_modules/express/lib/router/index.js:275:10) {
  errno: 'ETIMEDOUT',
  code: 'ETIMEDOUT',
  syscall: 'read',
  fatal: true
4

0 回答 0