Hosting on Railway - 401 error after inactivity

I actually find a way to prevent the bug,
The issue was with the DB configuration, not completely sure why but I guess the connection pool was containing Idled connection and when making a request after a long time of inactivity, the request couldn’t succeed.

I fix it by updating my config/database.js file :

module.exports = ({env}) => ({
  connection: {
    client: 'postgres',
    connection: {
      host: env('PGHOST', '127.0.0.1'),
      port: env.int('PGPORT', 5432),
      database: env('PGDATABASE', 'strapi'),
      user: env('PGUSER', 'strapi'),
      password: env('PGPASSWORD', 'password'),
      ssl: env.bool(true),
    },
    acquireConnectionTimeout: 5000,
    pool: {
      min: 0,
      max: 10,
      createTimeoutMillis: 8000,
      acquireTimeoutMillis: 8000,
      idleTimeoutMillis: 8000,
      reapIntervalMillis: 1000,
      createRetryIntervalMillis: 100,
    }
  },
});

The important part here is the “pool” object and particularly the min property that I’m setting to 0 instead of 2 by default.

1 Like