pg-promise hangs after six queries

北城以北 提交于 2019-12-12 05:27:10

问题


I'm working on a project using pg-promise. I've tried querying a few different ways with pg-promise but they all seem to cause it to hang after 6 queries.

It seems to me like the connections aren't being closed but I can't find anything in the documentation about closing a connection after a query.

Here's what I have

var cn = {
host: 'localhost',
port: 5432,
database: 'db',
user: 'user',
password: 'password'
};
var db = pgp(cn);

function query(sql, params) {
return db.task(function (t) {
    // this = t = task protocol context;
    // this.ctx = task config + state context;
    return t.query(sql, params);
})
.then(function (events) {
    // success;
    console.log(events);
})
.catch(function (error) {
    // error;    
});
}

I also tried using a shared connection, object but the documentation recommended using tasks. Does anyone know what's going on here?


回答1:


I'm not sure if this will be helpful to anyone in the future. But my problem was not return requests to the browser.

I hit the maximum number of connections and no responses to the browser made it appear to be hanging to me. I didn't realize requests is node/express won't automatically return like they do with php/apache.



来源:https://stackoverflow.com/questions/34521804/pg-promise-hangs-after-six-queries

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!