Error: Cannot read property 'name' of null
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.
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?
+1
+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 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.