[英]Why is node-postgres (pg) hanging when I call client.connect()?
我最近不得不將我的 vue.js 應用程序(后端的 node.js)的 node.js 版本從 v13.5.0 升級到 v14.5.0。 我重新安裝了所有節點包,升級了我必須升級的那些,現在應用程序掛起所有數據庫調用。 我們使用 pg (node-postgres) 進行數據庫調用。 我將 pg 升級到版本 7.18.2。
我們的初始化代碼如下所示:
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);
}
我將控制台日志放在對 this.init() 的調用周圍,如下所示:
console.log('before');
await this.init();
console.log('after');
'after' 永遠不會打印出來。
有誰知道我升級節點版本后為什么會掛起?
pg v.8.3.0 似乎解決了這個問題。 我通過運行 npm 安裝 pg 獲得了 v7.18.2。 似乎並不總是安裝最新版本。 npm install pg@latest 可以解決問題。
@gib65 升級到 v.8.3.0 對我來說也是一個訣竅,就是把我的頭放在 await 和 async 上。 還以為我又是n00b了……
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.