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

Error: Cannot read property 'name' of null #2705

Open
amrolabi opened this issue Feb 14, 2022 · 3 comments
Open

Error: Cannot read property 'name' of null #2705

amrolabi opened this issue Feb 14, 2022 · 3 comments

Comments

@amrolabi
Copy link

amrolabi commented Feb 14, 2022

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?

@shorman88
Copy link

+1

@juanrmn
Copy link

juanrmn commented Jan 10, 2023

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

@alxndrsn
Copy link
Contributor

@juanrmn I suspect #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 😉 OTOH the PR might give you clues to help reproduce if you're motivated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants