0

I am running a node application which uses ejs templating engine. I am using pg & pg-format library for executing queries. I have created connection using DATABASE_URL. The application is running fine on localhost but when it is deployed on production it throws an request timeout error (H12) when line for query executes.

router.post('/login', async (request,response)=>{

   const {email, password} = request.body;
   console.log('email : '+email+' passoword '+password);

  let errors = [], userId, objUser, isUserExist = false;

   if (!email || !password) {
     errors.push({ msg: 'Please enter all fields' });
     response.render('login',{errors});
    }
   console.log('pool.query : '+pool.query);
  
    await
    pool
   .query('SELECT Id, sfid, Name, email,PM_email__c FROM salesforce.Contact WHERE email = $1 AND password2__c = $2',[email,password])
   .then((loginResult) => {
         console.log('loginResult.rows[0]  '+JSON.stringify(loginResult.rows));
         if(loginResult.rowCount > 0)
         {
           userId = loginResult.rows[0].sfid;
           objUser = loginResult.rows[0];
           isUserExist = true;
         }
         else
         {
           isUserExist = false;
         }      
   }) 
   .catch((loginError) =>{
     console.log('loginError   :  '+loginError.stack);
     isUserExist = false;
   })

   
  await pool.query('SELECT sfid FROM salesforce.Team__c WHERE Manager__c =  $1 ',[userId])
  .then((teamQueryResult) => {
        if(teamQueryResult.rowCount > 0)
              objUser.isManager = true;
        else
              objUser.isManager = false; 

    console.log('is Manager ++++'+objUser.isManager);
  })
  .catch((teamQueryError) => {

  })

  if(isUserExist && errors.length == 0)
  {
    const token = jwt.sign({ user : objUser }, process.env.TOKEN_SECRET, {
      expiresIn: 8640000 // expires in 24 hours
    });
  
    response.cookie('jwt',token, { httpOnly: false, secure: false, maxAge: 3600000 });
    response.header('auth-token', token).render('dashboard',{objUser});
  }
  else
  {
    errors.push({ msg: 'Please enter correct email or correct password' });
    response.render('login',{errors});
  }
    
}) 

package.json

{
  "name": "myapp",
  "main": "app.js",
  "version": "0.0.0",
  "private": true,
  "scripts": {
    "start": "node ./bin/www"
  },
  "dependencies": {
    "@hapi/joi": "^17.1.1",
    "body-parser": "^1.19.0",
    "cloudinary": "^1.19.0",
    "connect-flash": "^0.1.1",
    "cookie-parser": "~1.4.4",
    "cookie-session": "^1.4.0",
    "cors": "^2.8.5",
    "debug": "~2.6.9",
    "dotenv": "^8.2.0",
    "ejs": "~2.6.1",
    "express": "^4.16.4",
    "express-ejs-layouts": "^2.5.0",
    "express-promise-router": "^3.0.3",
    "express-session": "^1.17.1",
    "express-validator": "^6.4.1",
    "g": "^2.0.1",
    "http-errors": "^1.8.0",
    "jsonwebtoken": "^8.5.1",
    "morgan": "~1.9.1",
    "multer": "^1.4.2",
    "nodemailer": "^6.4.6",
    "nodemon": "^2.0.4",
    "passport": "^0.4.1",
    "pg": "^7.17.1",
    "pg-format": "^1.0.4",
    "pg-promise": "^10.5.1"
  },
  "author": "amit,anukarsh,chitranshi",
  "license": "ISC",
  "description": ""
}

1
  • An H12 error occurs when your dyno is not returning the result to router (Heroku router) in time specified in worker config, default is 30 seconds. How long does your request take?
    – manjit5190
    May 2 at 14:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.