2 years ago
Hello folks, I’ve deployed a Node.js app with Express on Railway. Everything works fine, but every day around 1 AM, my app crashes because the connection to my database (also deployed on Railway) is lost. Do you have any tips to solve this strange issue? Here is my log from Railway:
node:events:495
throw er; // Unhandled 'error' event
^
Error: Connection terminated unexpectedly
at Connection. (/app/node_modules/pg/lib/client.js:132:73)
at Object.onceWrapper (node:events:631:28)
at Connection.emit (node:events:517:28)
at Socket. (/app/node_modules/pg/lib/connection.js:63:12)
at Socket.emit (node:events:517:28)
at TCP. (node:net:350:12)
Emitted 'error' event on Client instance at:
at Client.handleErrorEvent (/app/nodemodules/pg/lib/client.js:341:10)
at Connection. (/app/node_modules/pg/lib/client.js:150:16)
at Object.onceWrapper (node:events:631:28)
[… lines matching original stack trace …]
at TCP. (node:net:350:12)
Node.js v18.18.2
npm WARN config production Use --omit=dev instead.
6 Replies
2 years ago
you would need to make sure you are closing and flushing unused connections, this can often be done by setting the pool minimum to zero
@Brody thanks, for the reply. I’m using the default sequelize settings + idle timeout value of 50000. According to the docs by default it’s already zero (pool minimum) and max it’s 5
2 years ago
it seems somehow closed connections are still being kept in the pool