voxpelli/node-connect-pg-simple

Getting error "Error: connect ECONNREFUSED ip_address:5432" intermittently when the RDS is restarted.

Closed this issue · 2 comments

When the RDS is restarted, the application is unable to connect to it and shows the following error. This issue is intermittent.

Failed to prune sessions: connect ECONNREFUSED ip_address:5432
Failed to prune sessions: connect ECONNREFUSED ip_address:5432
Error: connect ECONNREFUSED ip_address:5432
     at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1144:16)
Error: connect ECONNREFUSED ip_address:5432
     at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1144:16)

The implementation:

let session = require('express-session');

let pgSession = require('connect-pg-simple')(session);
    const pg = require('pg');
    const sessionPool = new pg.Pool({
      host: process.env.DB_HOST,
      port: process.env.DB_PORT,
      user: process.env.DB_USERNAME,
      password: dbPass,
      database: "bludb",
      max: 100
    });
    let sessionOptions = {
      secret: "secret",
      resave: false,
      saveUninitialized: false,
      store: new pgSession({
        pool: sessionPool,
        ttl: process.env.SESSION_TIMEOUT / 1000,
        createTableIfMissing: true,
        pruneSessionInterval: 1800
      })
    };
    app.use(session(sessionOptions));

When the database is inaccessible its natural that there will be some errors I believe.

What's the behavior you would expect?

Closing as no more information has been provided.