node-postgres: ECONNRESET with unpooled connection / close
We’re in the process of bringing up our (normally AWS-based) stack on azure with a hosted PG instance. Azure apparently requires SSL (which may or may not be important, but it’s in the stack trace, so…)
We’re running into issues with unpooled connections (used to verify DB availability) in our periodic DB status tests. node version is 6.9.0; node-postgres version is 6.4. Code looks like this (w/o longjohn):
require('longjohn');
const pg = require('pg');
const DSN = 'postgres://uid:pwd@azure_db:5432/imp?ssl=true';
function status(cb) {
var start = Date.now();
var client = new pg.Client(DSN);
client.connect(function(err) {
if (err) {
return cb(err);
}
client.query("select 1 as pong", function(err, results) {
client.end();
if (err) {
return cb(err);
}
if (!results.rows || results.rows.length !== 1 || results.rows[0].pong !== 1) {
return cb(new Error("expected pong of 1"));
}
return cb(null, Date.now() - start);
});
});
}
setInterval(function() {
console.log(new Date().toISOString());
status(function(err, latency) {
if (err) {
console.error(err);
}
})
}, 5000);
… errors (after 5s) with this:
Error: read ECONNRESET
at exports._errnoException (util.js:1022:11)
at TLSWrap.onread (net.js:569:26)
---------------------------------------------
at Client.connect (/home/andrew/tmp/node_modules/pg/lib/client.js:184:7)
at status (/home/andrew/tmp/test-unpooled-pg.js:9:12)
at Timeout.<anonymous> (/home/andrew/tmp/test-unpooled-pg.js:32:5)
at ontimeout (timers.js:365:14)
at tryOnTimeout (timers.js:237:5)
at Timer.listOnTimeout (timers.js:207:5)
… seems like it may be related to https://github.com/brianc/node-postgres/issues/314 but unclear.
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Comments: 39 (10 by maintainers)
Commits related to this issue
- Ignore socket hangup when ending connection also with ssl (#1344). — committed to brianc/node-postgres by pasieronen 7 years ago
It seems that 7.4.1 didn’t fix the issue on our end. We’ve also tried the undocumented option
keepAlive
on pool creation and it seems it reduced the amount of time it happened (almost thinking it was fixed) but this morning it happened twice.I can’t seem to figure out where the issue is coming from, to be honest.
Any idea on when the above PR will be merged? Would love to remove the workarounds in our code base written to avoid this issue.
Your suggestion from #314 worked for me (adding
this.stream.end();
). If it also works for @aahoughton I can create PR with fix.@brianc any update about this problem? Because it’s still occur.
@cryptcoin-junkey I closed it because there was to many changes in the meantime, and I thought it’s already been solved.