node-postgres icon indicating copy to clipboard operation
node-postgres copied to clipboard

Error: Cannot read property 'name' of null

Open amrolabi opened this issue 3 years ago • 1 comments

Hi. We have updated our set up from

nodejs 12.16.1 psql (PostgreSQL) 10.1 pg 7.11.0

to:

nodejs 14.18.1 psql (PostgreSQL) 10.1 (also on 13.1) pg 8.7.1

After that, when any type error happening on callback function, the following error occurring infinitely :

TypeError: Cannot read property 'name' of null at Client._handleParseComplete (/Users/amr/workspace/node_modules/pg/lib/client.js:367:26) at Connection.emit (events.js:314:20) at /Users/amr/workspace/node_modules/pg/lib/connection.js:114:12 at Parser.parse (/Users/amr/workspace/node_modules/pg-protocol/dist/parser.js:40:17) at Socket. (/Users/amr/workspace/node_modules/pg-protocol/dist/index.js:11:42) at Socket.emit (events.js:314:20) at addChunk (_stream_readable.js:297:12) at readableAddChunk (_stream_readable.js:272:9) at Socket.Readable.push (_stream_readable.js:213:10) at TCP.onStreamRead (internal/stream_base_commons.js:188:23)


Before the update, our code had been working properly for several years.

Sample of code that raises the error:

var pg = require('pg'); let newPool = function() {

if(typeof PG_POOL == 'undefined') {
	
	PG_POOL = new pg.Pool({
		'max':					2,
		'port':			 		5432,
		'user':			 		'user',
		'host':			 		'host',
		'password':		 		'pass',
		'database':		 		'database',
		'idleTimeoutMillis':	60000
	});

	PG_POOL.on('error', (err, client) => {
		console.error(err);
	});
}

return PG_POOL;

};

let ExecuteQuery = function(sql, bindVars, callback) { var pool = newPool(); pool.query(sql, bindVars, (err, result) => { return callback(err, result); });

}

ExecuteQuery("select 1 from tableX WHERE id = $1", [1], function(err, res) { if(err) { console.error(err); return; } console.log(res.a.b); // whatever TypeError caused by the application });

Any advice?

amrolabi avatar Feb 14 '22 18:02 amrolabi

+1

shorman88 avatar Feb 15 '22 16:02 shorman88

+1 It seems to happen randomly to us. We couldn't reproduce it so far, but still happening like once or twice a week 🤷

juanrmn avatar Jan 10 '23 10:01 juanrmn

@juanrmn I suspect https://github.com/brianc/node-postgres/pull/2836 might fix many of these similar-looking bugs. Difficulty reproducing is a common theme, so if you feel like testing the patch in prod that would be helpful :wink: OTOH the PR might give you clues to help reproduce if you're motivated.

alxndrsn avatar Jan 10 '23 11:01 alxndrsn