Connection terminated unexpectedly after 5 minutes

I’ve successfully deployed a Remix/Node.js application on Koyeb, which connects to a PostgreSQL database also hosted on Koyeb. It is a service, which contains a web page and has an API to listen to webhooks and after deployment I can correctly access the web page. However, I’m encountering a recurring issue where, consistently 5 minutes post-deployment, the application becomes unresponsive. The logs indicate:

Application exited with code 1. This usually indicates an application failure. Check that the command used to launch your application is correct.

I’m wondering if this behavior is related to the health checks. Apparently health checks are done to the port 8000, which I would expect are ok if I am able to access the web page that is deployed and right after deployment it says:

Instance is healthy. All health checks are passing.

After 5 minutes I get this logs and the app is terminated within 15 minutes:

const error = this._ending ? new Error('Connection terminated') : new Error('Connection terminated unexpectedly')

The deploy:

[remix-serve] http://localhost:8000 (

In my package.json

“start”: “remix-serve ./build/index.js”,

This topic was discussed on our slack community.

The root cause of this seemed to be the database automatically sleeping after 5m of inactivity.

So there is this error:
const error = this._ending ? new Error(‘Connection terminated’) : new Error(‘Connection terminated unexpectedly’)
Which indicates that connection to DB is lost
This happens around 5min after the app starts, this would suggest that it’s related to DB sleeping:
Databases follow the serverless pattern by freeing resources that are not being actively used. After 5 minutes of inactivity, your database’s compute resources will automatically sleep. They wake up at the first new query with only a minor delay.

For example, here someone suggests a simple snippet which should fix the issue `pool.on('error')` doesn’t populate client error listeners as well · Issue #2439 · brianc/node-postgres · GitHub
There are more related issues linked there.