When I try bulk query in nodejs with promise.all I got ECONNREFUSED error after some number of query resulted in success.
I am building node server for my web application. I made some queries resulted from AJAX requests from client. They all worked fine till now.
I tried to load data from excel to some number of tables (i use pg module). I wrote a code that insert records after reading if there is not a same record. I used promise to make queries. But it made some queries and then start to get ECONNREFUSED error.
- I have changed max_connections to 10000 and shared_buffers to 25000MB. And restart postgres server
- I have changed max_connections to 1000 and shared_buffers to 2500MB.And restart postgres server
- I have changed max_connections to 300 and shared_buffers to 2500MB. And restart postgres server
- I have changed my code from POSTGRESQL Pool to POSTGRESQL Client
I have omitted some query in promise array
but nothing changed. Almost 180 records were inserted at all. Then got en error.
function loadData(auditArrayObject){
return new Promise(function (resolve, reject) {
let promises=[
loadAuditItem(auditArrayObject.audit,
auditArrayObject.auditVersion),
loadProcesses(auditArrayObject.processArray),
loadControlAims(auditArrayObject.controlAimArray),
loadCriterias(auditArrayObject.criteriaArray),
loadParameters(auditArrayObject.parameterArray),
]
Promise.all(promises)
.then(objectsWithId=>{
......
}
}
function loadProcesses(processArray){
return new Promise(function (resolve, reject) {
let promises=[];
for(let i=0;i<processArray.length;i++){
let process= new Process(null,processArray[i],false)
let promise= postGreAPI.readProcessByName(process.name)
.then(resultProcess=>{
if (!resultProcess) {
postGreAPI.createProcess(process)
.then(createdProcess=>{
resolve(createdProcess)
})
.catch(err=>{
reject({msg:"createProcess
hata aldı",err:err})
})
} else {
return (resultProcess)
}
})
.catch(err=>{
reject({msg:"readProcessByName
hata aldı",err:err})
})
promises.push(promise)
}
Promise.all(promises)
.then(processArray=>{
resolve({key:"Process",value:processArray})
})
.catch(err=>{
reject({msg:"Processlerden birisi insert edilemedi",err:err})
})
});
}
postGreAPI.readProcessByName:
var readProcessByName = function (name){
return new Promise(function (resolve, reject) {
let convertedName=convertApostrophe(name)
let query = "SELECT * FROM process WHERE name='"
+ convertedName + "'"
queryDb(query)
.then(result=>{
if (result.rows.length>0){
let process = new Process(result.rows[0].id,
result.rows[0].name,
result.rows[0].isactive);
resolve(process)
}else{
resolve(null)
}
})
.catch(err=>{
reject(err)
})
})
}
queryDb:
var queryDb2 = function (query,params) {
return new Promise(function (resolve, reject) {
let pool = new PostGre.Pool(clientConfig);
pool.connect(function(err, client, done) {
if(err) {
return reject (err);
}
client.query(query,params, function(err, result) {
done();
if(err) {
return reject (err);
}
resolve(result)
});
});
})
}
And error is :
Error: connect ECONNREFUSED 127.0.0.1:5432
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1113:14)
errno: 'ECONNREFUSED',
code: 'ECONNREFUSED',
syscall: 'connect',
address: '127.0.0.1',
port: 5432 }
Actually i have succed that load before my laptop configuration changed. Before there was a windows 7 but now windows 10.