pg-promise hangs after six queries

2019-09-08 05:47发布

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?

标签: pg-promise
1条回答
The star\"
2楼-- · 2019-09-08 06:20

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.

查看更多
登录 后发表回答