5

I recently had to upgrade my node.js version for my vue.js application (node.js on the backend) from v13.5.0 to v14.5.0. I reinstalled all my node packages, upgrading the ones I had to upgrade, and now the application hangs on all DB calls. We are using pg (node-postgres) for our database calls. I upgraded pg to version 7.18.2.

Our initialization code looks like this:

constructor() {
  this.pg = require('pg');
  this.client = null;
  this.initPromise = null;
}

async init() {
  if (!this.initPromise) {
    this.client = new this.pg.Client({
      application_name: 'Back end',
      ssl: {
        rejectUnauthorized: false
      }
    });
    this.initPromise = this.client.connect();
  }
  return this.initPromise;
}

async query(query, params) {
  await this.init();
  return await this.client.query(query, params);
}

I put console logs around the call to this.init() as follows:

console.log('before');
await this.init();
console.log('after');

'after' never prints out.

Does anyone know why it hangs now that I've upgrade my node version?

4
  • The init method should not be async since you're not using await inside of it, but that's unrelated to the problem Commented Jul 13, 2020 at 13:03
  • Where are you passing the connection details and credentials to the client? Commented Jul 13, 2020 at 13:04
  • What version of node-postgres did you have installed previsously? Commented Jul 13, 2020 at 13:04
  • According to the node-postgres documents (node-postgres.com/features/connecting), it grabs the connection details from the environment variables. But I tried passing them to the Client constructor explicitly: this.client = new this.pg.Client({host: ..., database: ..., etc.}); but to no avail. I had 7.8.0 installed previously. Commented Jul 13, 2020 at 14:19

2 Answers 2

14

It seems that pg v.8.3.0 solves this problem. I got v7.18.2 from running npm install pg. Seems that doesn't always install the latest version. npm install pg@latest does the trick.

Sign up to request clarification or add additional context in comments.

3 Comments

Had the same problem, spent a good 2 hours trying to fix this. Can confirm updating to the the latest version fixed it.
The root cause is that node 14 introduced a change that broke pg. Upgrading pg solves it. I just spent ages trying to understand why simple postgres code wasn't working in dev but was fine in prod which uses node 12. More info: stackoverflow.com/questions/61611039/…
I was about to lose my mind until I stumbled upon this. THANK YOU!
0

@gib65 upgrading to v.8.3.0 did the trick for me too was banging my head on await and async. thought i was being a n00b again...

1 Comment

Hi madmus, I suppose it is preferable to add a comment to reply to a comment. Your comment doesn't seems to be an answer to the question.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.