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

Most upvoted comments

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

error fetching client from pool { error: password authentication failed for user "username"
    at Connection.parseE (/usr/src/app/node_modules/pg/lib/connection.js:539:11)
    at Connection.parseMessage (/usr/src/app/node_modules/pg/lib/connection.js:366:17)
    at Socket.<anonymous> (/usr/src/app/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: 93,
  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: 'auth.c',
  line: '285',
  routine: 'auth_failed' }

My Test environment:

  • Docker Node v6.0.0

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 as utf8, not as binary if no encoding is specified.