2

Backend Setup:

  • Node.js/Express server running on port 5000
  • AWS S3 (for images)
  • AWS RDS Mysql (for data)

Hi guys,

I'm a frontend guy, so I don't know much about backend, I just started learning.

I have a Node.js/Express server on port 5000 that I use to connect to an S3 bucket and an RDS Mysql database, that is enough for the React frontend I'm developing at the moment.

I use nodemon to deal with disconnects and reconnect automatically. It used to work just fine 24/7, but I must have changed something during the last 3 months and now it crashes several times a day and I have to restart the server manually. It's not a huge deal but I would like to learn how to deal with it.

Here's the error I keep getting:

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

Obviously the second part happens when I try to connect without knowing the server has already crashed.

There are plenty of posts on stackoverflow about similar ECONNRESET problems, so it's very possible that my exact problem has already been replied somewhere else, but to be honest I'm just not good enough at this yet to assimilate the answer by myself, I could use some pointers as to what files the problem seems to be in or whatever you could tell me.

I have seen in several posts that the best way to deal with this kind of problem is to set error listeners, and I'm happy to do just that, but to be honest I don't know where to start because the problem happens when I'm not using the server usually, like at night or when I'm not even in front of the computer. I have no idea how to reproduce the problem on my own, it just happens by itself whenever it happens, so that's why it's so hard for me to know where to start. I looked at the logs on my S3 and RDS Mysql and didn't see anything that seemed directly connected to this.

Could you offer me some pointers based on what you see here? I have some possible ideas:

  • could it be the router at index.js causing this?
  • when I look at my RDS Mysql database panel I see at the moment there are 3 active connections, even though I stopped working like 2 hours ago. Could it be that those connections timing out are causing this? (read this in another post)
  • could it be meProfileImageData.js that should get error listening first?

That's all I have for now, any ideas or pointers are highly welcome, and I'll be glad to run any tests or install any necessary additional software to troubleshoot this if you feel like putting in the time to help me.

Thanks


EDIT 1: had a new error today that seems to point at connections being closed automatically and Node.js not dealing with it before there is an attempt to connect:

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
Worthing
  • 37
  • 7
  • Looks like there is a problem with mysql server. Did you look at this post ? [link](http://jtdz-solenoids.com/stackoverflow_/questions/22900931/mysql-giving-read-econnreset-error-after-idle-time-on-node-js-server) – user2349470 Dec 27 '20 at 06:37
  • Thanks so much! I had not seen that post, no. It's quite old so I would usually assume that the issues they're describing must be fixed by now if it was indeed a bug, I usually try to look at newer posts. But pooling connections is mentioned, which is something I need to get into for sure, I was hoping I could run a single connection solidly first so I would know what I'm actually doing :) One problem at a time :D – Worthing Dec 27 '20 at 07:00

0 Answers0