Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Doesn't work under Node.js 6.0.0 #1000

Closed
vitaly-t opened this issue Apr 27, 2016 · 31 comments
Closed

Doesn't work under Node.js 6.0.0 #1000

vitaly-t opened this issue Apr 27, 2016 · 31 comments
Labels

Comments

@vitaly-t
Copy link
Contributor

vitaly-t commented Apr 27, 2016

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)
@migolo
Copy link

migolo commented Apr 27, 2016

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

@jadbox
Copy link
Contributor

jadbox commented Apr 27, 2016

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

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

@jadbox
Copy link
Contributor

jadbox commented Apr 27, 2016

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?

@vitaly-t
Copy link
Contributor Author

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.

@vitaly-t
Copy link
Contributor Author

vitaly-t commented Apr 27, 2016

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

@slvnperron
Copy link

Same issue here

@ignitenet-martynas
Copy link
Contributor

Hello everyone,

Here's what fixes the Node v6.0.0 problem:

https://github.com/ignitenet-martynas/node-postgres/commit/77560fe1bbc80ba0a629720161d81dbb6286166d

@Canop
Copy link

Canop commented Apr 27, 2016

I confirm it works for me

@anyong
Copy link

anyong commented Apr 27, 2016

Works for me too.

@vitaly-t
Copy link
Contributor Author

vitaly-t commented Apr 27, 2016

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

@vitaly-t
Copy link
Contributor Author

The issue has been resolved with 4.5.5 release.

Thank you @ignitenet-martynas and @brianc 👍

@brianc
Copy link
Owner

brianc commented Apr 27, 2016

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

@ChALkeR
Copy link

ChALkeR commented May 1, 2016

Btw, judging by the fix, this is probably due to by nodejs/node#5522, not the Buffer changes. crypto now treats strings as utf8, not as binary if no encoding is specified.

@ignitenet-martynas
Copy link
Contributor

ignitenet-martynas commented May 1, 2016

Precisely, @ChALkeR.

@ivarconr ivarconr mentioned this issue May 1, 2016
11 tasks
andywhite37 added a commit to andywhite37/postgrator that referenced this issue May 16, 2016
- There is a change in `Buffer` in node 6 that causes an issue with
  authentication in the `pg`/`pg.js` modules.
- See brianc/node-postgres#1018
- Which references: brianc/node-postgres#1000
- This commit changes the pg library dependency to the version that
  contains the fix for this issue.
@nicbarker
Copy link

Sorry for zombying this issue but I seem to be having the same problem despite upgrading to pg 4.5.5 on node 6.2.1. Same error: password authentication failed for user. I'm using RDS if that helps - is there anyone else still experiencing this issue?

@nicbarker
Copy link

Apologies - this was my fault. Another issue masquerading as this one that I've managed to fix.

joelmukuthu referenced this issue in One-com/node-mocha-docker-postgres Jun 30, 2016
Makes it possible to use this in Node.js 6
@ijunaid8989
Copy link

I am getting the same error right now am on node 6.0.0 and my lib/client also has var outer = Client.md5(Buffer.concat([new Buffer(inner), msg.salt]));

@taufikmas
Copy link

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)

@vitaly-t
Copy link
Contributor Author

vitaly-t commented Jun 8, 2017

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

@taufikmas
Copy link

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

@vitaly-t
Copy link
Contributor Author

vitaly-t commented Jun 8, 2017

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

@brianc
Copy link
Owner

brianc commented Jun 8, 2017

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

@taufikmas
Copy link

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

@taufikmas
Copy link

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

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

@taufikmas
Copy link

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

@endermaxximum
Copy link

@ignitenet-martynas
Copy link
Contributor

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

@endermaxximum
Copy link

okay.thank you

@endermaxximum
Copy link

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');
});`

@charmander
Copy link
Collaborator

charmander commented Aug 8, 2018

@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",
});

@endermaxximum
Copy link

Thank you so much.
@charmander

@charmander charmander added the bug label Dec 6, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests