Skip to content

Doesn't work under Node.js 6.0.0 #1000

Description

@vitaly-t

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)

Activity

  1. migolo commented on Apr 27, 2016

    @migolo

    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
  2. jadbox commented on Apr 27, 2016

    @jadbox
    Contributor

    Yep, same here as @migolo and @vitaly-t

    (also, I think I need to wear sunglasses to fit into this community)

  3. jadbox commented on Apr 27, 2016

    @jadbox
    Contributor

    I wonder how this happened? There shouldn't be an API breaking change in v6 other than the worker process API.

    Btw, what's this file: 'auth.c' file being mentioned?

  4. vitaly-t commented on Apr 27, 2016

    @vitaly-t
    ContributorAuthor

    Btw, what's this file: 'auth.c' file being mentioned?

    That's where all the authentication mambo-jumbo happens inside PostgreSQL server code. It is always mentioned on any authentication-related error.

  5. vitaly-t commented on Apr 27, 2016

    @vitaly-t
    ContributorAuthor

    I've done some initial debugging, and I am almost certain the issue is caused by one of the changes to the Buffer.

    From the change-log:


    The following significant changes have been made since the previous Node.js v5.0.0 release:

    • Buffer
      • New Buffer constructors have been added
        #4682 and
        #5833.
      • Existing Buffer() and SlowBuffer() constructors have been deprecated
        in docs #4682 and
        #5833.
      • Previously deprecated Buffer APIs are removed
        #5048,
        #4594.
      • Improved error handling #4514.
      • The Buffer.prototype.lastIndexOf() method has been added
        #4846.

    For example, if I do something like this:

    Connection.prototype.parseCString = function(buffer) {
      console.log('BUFFER:', buffer.length);
      var start = this.offset;
      while(buffer[this.offset++] !== 0) { }
      return buffer.toString(this.encoding, start, this.offset - 1);
    };

    in file connection.js, i see immediate change in the received buffer length as I change to Node.js 6.0.0

  6. slvnperron commented on Apr 27, 2016

    @slvnperron

    Same issue here

  7. ignitenet-martynas commented on Apr 27, 2016

    @ignitenet-martynas
    Contributor
  8. Canop commented on Apr 27, 2016

    @Canop

    I confirm it works for me

  9. anyong commented on Apr 27, 2016

    @anyong

    Works for me too.

  10. vitaly-t commented on Apr 27, 2016

    @vitaly-t
    ContributorAuthor

    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 ;)

  11. vitaly-t commented on Apr 27, 2016

    @vitaly-t
    ContributorAuthor

    The issue has been resolved with 4.5.5 release.

    Thank you @ignitenet-martynas and @brianc 👍

  12. brianc commented on Apr 27, 2016

    @brianc
    Owner

    Thanks for your help with reporting it & digging in and finding it was an issue with the buffer @vitaly-t!!

  13. added a commit that references this issue on Apr 27, 2016
  14. 8 remaining items

  15. taufikmas commented on Jun 8, 2017

    @taufikmas

    DOESnt work for me.
    have same problem,,and i try your solution but still error, cannot 'gulp serve'
    hope your help.

    PS C:\webproj\dreamhouse-web-app> gulp serve
    [10:45:36] Using gulpfile C:\webproj\dreamhouse-web-app\gulpfile.js
    [10:45:36] Starting 'clean'...
    [10:45:36] Finished 'clean' after 69 ms
    [10:45:36] Starting 'watch'...
    [10:45:36] Starting 'sass'...
    [10:45:36] Starting 'html'...
    [10:45:36] Starting 'fonts'...
    [10:45:36] Starting 'scripts'...
    [10:45:36] Finished 'scripts' after 118 ms
    [10:45:36] Finished 'html' after 160 ms
    [10:45:36] Finished 'fonts' after 177 ms
    [10:45:38] Finished 'sass' after 2.14 s
    7.6 MB bytes written (9.89 seconds)
    [10:45:49] Finished 'watch' after 13 s
    [10:45:49] Starting 'serve'...
    Listening at: http://localhost:8200
    [10:45:49] Finished 'serve' after 302 ms
    events.js:160
    throw er; // Unhandled 'error' event
    ^

    error: password authentication failed for user "taufikmas"
    at Connection.parseE (C:\webproj\dreamhouse-web-app\node_modules\pg\lib\connection.js:539:11)
    at Connection.parseMessage (C:\webproj\dreamhouse-web-app\node_modules\pg\lib\connection.js:366:17)
    at Socket. (C:\webproj\dreamhouse-web-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:176:18)
    at Socket.Readable.push (_stream_readable.js:134:10)
    at TCP.onread (net.js:547:20)

  16. vitaly-t commented on Jun 8, 2017

    @vitaly-t
    ContributorAuthor

    @fixduino did you test it under Node 4.x? Which version of node-postgres are you using?

  17. taufikmas commented on Jun 8, 2017

    @taufikmas

    i use latest node 6.0 . win10.
    is node jss 6.0 not support pg 4.5.5?
    i try for this tutorial https://github.com/dreamhouseapp/dreamhouse-web-app

  18. vitaly-t commented on Jun 8, 2017

    @vitaly-t
    ContributorAuthor

    @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.

  19. brianc commented on Jun 8, 2017

    @brianc
    Owner

    @fixduino I'd need to see your code but it looks like you're using the wrong password.

  20. taufikmas commented on Jun 8, 2017

    @taufikmas

    i never put my password. where is location for set password? thx

  21. taufikmas commented on Jun 8, 2017

    @taufikmas

    client.js -- https://pastebin.com/XQYs5xWv

    conection-parameters.js -- https://pastebin.com/44mHmsgh
    thx for help

  22. taufikmas commented on Jun 9, 2017

    @taufikmas

    SOLVED.. just a little mistake to set parameter..
    in server.js
    var connectionString = process.env.DATABASE_URL || 'postgres://postgres:admin@localhost:5432/dreamhouse'; //postgres://YourUserName:YourPassword@localhost:5432/YourDatabase";
    thanks all.

    win10. nodejs 6.0

  23. endermaxximum commented on Aug 6, 2018

    @endermaxximum
  24. ignitenet-martynas commented on Aug 6, 2018

    @ignitenet-martynas
    Contributor

    @endermaxximum Well the fix has been integrated into node-postgres quite a while ago therefore I deleted the fork...

  25. endermaxximum commented on Aug 6, 2018

    @endermaxximum

    okay.thank you

  26. endermaxximum commented on Aug 8, 2018

    @endermaxximum

    This is the error that I got.
    image

    could you help me what wrong with my code? @ignitenet-martynas

    here is my code: `var express = require('express'),
    path = require('path'),
    bodyParser = require('body-parser'),
    cons = require('consolidate'),
    dust = require('dustjs-helpers'),
    pg = require('pg'),
    app = express();
    var pool = new pg.Pool()
    // DB Connect String
    // from owner Loaserver pass 00000000
    var connect ="postgres://Loraserver:00000000@localhost/Lopicaserver";

    // Assign Dust Engine to .dust Files
    app.engine('dust', cons.dust);

    // Set Default Ext .dust
    app.set('view engine', 'dust');
    app.set('views', __dirname + '/views');

    // Set Public Folder
    app.use(express.static(path.join(__dirname, 'public')));

    // Body Parser Middleware
    app.use(bodyParser.json());
    app.use(bodyParser.urlencoded({ extended: false }));

    app.get('/', function(req, res){

    //connect using created pool
    pool.connect(function(err, client, done) {
    if(err) {
    return console.error('error fetching client from pool', err);
    }
    client.query('SELECT * FROM public.loradata', function(err, result){
    if(err){
    return console.error('error running query', err);
    }
    res.render('index', {loradata: result.rows});
    done();
    });
    });
    });

    // Server
    app.listen(3000, function(){
    console.log('Server Started On Port 3000');
    });`

  27. charmander commented on Aug 8, 2018

    @charmander
    Collaborator

    @endermaxximum Your connection string isn’t used anywhere. Pass it to the pool constructor (documentation):

    var pool = new pg.Pool({
        connectionString: "postgres://Loraserver:00000000@localhost/Lopicaserver",
    });
  28. endermaxximum commented on Aug 8, 2018

    @endermaxximum

    Thank you so much.
    @charmander

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions