node-postgres: Unhandled 'error' event thrown when the connection password doesn't match
When I connect to an existing database with the connect username but the wrong password, I got an unhandled exception using the following code. The parameter err is set, but the exception is still thrown.
pg.connect(dbURL, function(err, client, done) {
if(err) {
return console.error('error fetching client from pool', err);
}
client.query('SELECT $1::int AS number', ['1'], function(err, result) {
//call `done()` to release the client back to the pool
done();
if(err) {
return console.error('error running query', err);
}
console.log(result.rows[0].number);
//output: 1
client.end();
});
});
About this issue
- Original URL
- State: closed
- Created 9 years ago
- Comments: 38 (20 by maintainers)
Commits related to this issue
- Suggested fix for Postgres errors causing node process to crash https://github.com/brianc/node-postgres/issues/746#issuecomment-13421947 0 — committed to jecarroll/node-postgres by jecarroll 8 years ago
- Fix ECONNRESET error emitted after failed connect On Windows, after a connect attempt has failed, an error event with ECONNRESET is emitted after the real connect error is propagated to the connect c... — committed to magnushiie/node-postgres by magnushiie 7 years ago
- Fix ECONNRESET error emitted after failed connect (#1230) On Windows, after a connect attempt has failed, an error event with ECONNRESET is emitted after the real connect error is propagated to the ... — committed to brianc/node-postgres by magnushiie 7 years ago
+1000
The same error is thrown when we pass an invalid connection:
Other than that, it is 100% reproducible for me, for both invalid user name and invalid password.
It’s been way too long for such a critical issue to just sit here and nothing being done about it. Very frustrating.
I have a number of tests now for pg-promise commented out because of this error, which just kills jasmine framework that I’m using for testing.
Should have been labelled as a bug, at least, as it definitely is.