【发布时间】:2015-04-11 19:52:30
【问题描述】:
我有一个使用 postgres amazon RDS 的 amazon beanstalk 节点应用程序。要将节点与 postgres 接口,我使用node postgres。代码如下所示:
var pg = require('pg'),
done,client;
function DataObject(config,success,error) {
var PG_CONNECT = "postgres://"+config.username+":"+config.password+"@"+
config.server+":"+config.port+"/"+config.database;
self=this;
pg.connect(PG_CONNECT, function(_error, client, done) {
if(_error){ error();}
else
{
self.client = client;
self.done = done;
success();
}
});
}
DataObject.prototype.add_data = function(data,success,error) {
self=this;
this.client.query('INSERT INTO sample (data) VALUES ($1,$2)',
[data], function(_error, result) {
self.done();
success();
});
};
为了使用它,我创建了我的数据对象,然后在每次出现新数据时调用 add_data。在 add_data 中,我调用 'this/self.done()' 将连接释放回池。现在,当我反复提出这些请求时,client.query 永远不会回来。在什么情况下会导致数据库接口阻塞/无响应?
【问题讨论】:
标签: node.js postgresql amazon-elastic-beanstalk amazon-rds