node-postgres: Doesn't work under Node.js 6.0.0
If we take the example on the main page:
var pg = require('pg');
var conString = "postgres://username:password@localhost/database";
//this initializes a connection pool
//it will keep idle connections open for a (configurable) 30 seconds
//and set a limit of 10 (also configurable)
pg.connect(conString, 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
});
});
And simply switch to Node.js 6.0.0, we are immediately getting an error:
error fetching client from pool { error: password authentication failed for user "postgres"
at Connection.parseE (D:\NodeJS\tests\node_modules\pg\lib\connection.js:539:11)
at Connection.parseMessage (D:\NodeJS\tests\node_modules\pg\lib\connection.js:366:17)
at Socket.<anonymous> (D:\NodeJS\tests\node_modules\pg\lib\connection.js:105:22)
at emitOne (events.js:96:13)
at Socket.emit (events.js:188:7)
at readableAddChunk (_stream_readable.js:172:18)
at Socket.Readable.push (_stream_readable.js:130:10)
at TCP.onread (net.js:535:20)
name: 'error',
length: 115,
severity: 'FATAL',
code: '28P01',
detail: undefined,
hint: undefined,
position: undefined,
internalPosition: undefined,
internalQuery: undefined,
where: undefined,
schema: undefined,
table: undefined,
column: undefined,
dataType: undefined,
constraint: undefined,
file: 'src\\backend\\libpq\\auth.c',
line: '304',
routine: 'auth_failed' }
i.e. authentication doesn’t work under the newly released Node.js 6.0.0
My Test environment:
- Windows 10, 64-bit
- Node.js 6.0.0 (released)
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Reactions: 27
- Comments: 31 (13 by maintainers)
Commits related to this issue
- Updated node-postgres to v4.5.5 Fixes the Node 6.0.0 issue: https://github.com/brianc/node-postgres/issues/1000 — committed to subblue/massive-js by subblue 8 years ago
- fix postgres driver incompatibility with node 6 see https://github.com/brianc/node-postgres/issues/1000 — committed to Canop/miaou by Canop 8 years ago
- Possible fix for pg issue in node 6.x - There is a change in `Buffer` in node 6 that causes an issue with authentication in the `pg`/`pg.js` modules. - See https://github.com/brianc/node-postgres/i... — committed to andywhite37/postgrator by andywhite37 8 years ago
- Update pg to 6.0.1 Makes it possible to use this in Node.js 6 — committed to One-com/node-mocha-docker-postgres by deleted user 8 years ago
- Update package.json Make it possible to use the lib on node versions >= 6.0.0 https://github.com/brianc/node-postgres/issues/1000 — committed to AndyMathys/node-pg-jobs by AndyMathys 7 years ago
Hello everyone,
Here’s what fixes the Node v6.0.0 problem:
https://github.com/ignitenet-martynas/node-postgres/commit/77560fe1bbc80ba0a629720161d81dbb6286166d
The issue has been resolved with 4.5.5 release.
Thank you @ignitenet-martynas and @brianc 👍
Yep, same here as @migolo and @vitaly-t
(also, I think I need to wear sunglasses to fit into this community)
Thanks for your help with reporting it & digging in and finding it was an issue with the buffer @vitaly-t!!
I get the same error
My Test environment:
Same issue here
I confirm this to be the fix indeed! Thank you @ignitenet-martynas !
So it was the
Buffer
as I thought 😃@brianc Now we just need the PR to make into a new release 😉 And I think it should be 4.6.0 😉
@fixduino I’d need to see your code but it looks like you’re using the wrong password.
@fixduino try Node.js 4.x, your problem could be unrelated, i.e. if you still get the same error, then it is not related, and you simply got your password wrong.
Apologies - this was my fault. Another issue masquerading as this one that I’ve managed to fix.
Btw, judging by the fix, this is probably due to by https://github.com/nodejs/node/pull/5522, not the Buffer changes.
crypto
now treats strings asutf8
, not asbinary
if no encoding is specified.