-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Cannot read property 'handleRowDescription' of null #2556
Comments
Can you include a self contained code sample to replicate the problem?
…On Sat, May 29, 2021 at 10:54 AM SergeiLL ***@***.***> wrote:
Hi.
We have updated our set up from
nodejs 14.4.0
Ubuntu 18.04.4 LTS
psql (PostgreSQL) 12.1
pg 8.2.1
to:
nodejs 16.1.0
Ubuntu 20.04.2 LTS
psql (PostgreSQL) 12.6
pg 8.6
After that, the pg connection started crashing.
Before the update, our code had been working properly for several years.
The error is floating. The error can appear several times a day, or maybe
after a few days (7-8).
2021-05-29T09:42:16.192Z TypeError: Cannot read property
'handleRowDescription' of null
at Client._handleRowDescription
(/home/user_name/node_modules/pg/lib/client.js:340:22)
at Connection.emit (node:events:365:28)
at Connection.emit (node:domain:470:12)
at /home/user_name/node_modules/pg/lib/connection.js:114:12
at Parser.parse
(/home/user_name/node_modules/pg-protocol/dist/parser.js:40:17)
at Socket. (/home/user_name/node_modules/pg-protocol/dist/index.js:11:42)
at Socket.emit (node:events:365:28)
at Socket.emit (node:domain:470:12)
at addChunk (node:internal/streams/readable:314:12)
at readableAddChunk (node:internal/streams/readable:289:9) TypeError:
Cannot read property 'handleRowDescription' of null
at Client._handleRowDescription
(/home/user_name/node_modules/pg/lib/client.js:340:22)
at Connection.emit (node:events:365:28)
at Connection.emit (node:domain:470:12)
at /home/user_name/node_modules/pg/lib/connection.js:114:12
at Parser.parse
(/home/user_name/node_modules/pg-protocol/dist/parser.js:40:17)
at Socket. (/home/user_name/node_modules/pg-protocol/dist/index.js:11:42)
at Socket.emit (node:events:365:28)
at Socket.emit (node:domain:470:12)
at addChunk (node:internal/streams/readable:314:12)
at readableAddChunk (node:internal/streams/readable:289:9)
Any advice?
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#2556>, or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAAMHIKTCYB6J7CB2HDVC5LTQEE47ANCNFSM45YNMEIA>
.
|
Also, are you able to revert just the version of pg for a while? It’d be nice to rule out all the other upgrades if possible. :) |
Hi. |
Can you include a self-contained example of code *similar* to the code
causing a problem? Without any code there's really not much I can do to
look into the issue - all the tests in this project pass on multiple
versions of node & postgres.
…On Tue, Jun 15, 2021 at 2:24 AM SergeiLL ***@***.***> wrote:
Hi.
I downgraded PG to 8.2.1. the bug was repeated.
Unfortunately, I cannot show the code. The project is commercial.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#2556 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAAMHIMGUGAMTOTJYQ6G7TTTS353FANCNFSM45YNMEIA>
.
|
@SergeiLL did you ever figure this one out?....we are seeing the same thing.... |
@repl-chris |
Same issue after upgrade from node8, pg 7.4.1 to node 14, pg 8.6 |
@liam-lai Do you have code/setup details to reproduce the issue? |
@charmander nah, unfortunately. I am now trying to monitor, it happens intermediately. Will share if I get more details Update: Looks like its my data issue, there is something like |
FYI we found the cause of ours - using pg-query-stream, we were sometimes releasing the client before the stream had been read all the way to the end....when this happens the client is returned to the pool and it eventually throws that error and crashes the process. We made the change to call |
Same issue after upgrade from 7.18.2 to 8.2.1 (which we only did because using 7.18.2 on Node 14 was thoroughly broken) Windows Server 2019 I tried to reproduce artificially by running the code below (and other variations of it - swapping order of SLOW, IMMEDIATE and ERROR queries with each other) and hitting with app.get('/abc', ( req, res ) => {
for ( let i = 0; i < 5000; i++ ) {
if ( i % 40 === 0 ) {
// SLOW
// Millions of rows, no indexes
helper.query(`SELECT * FROM zip_codes where city_name ilike 'a%'`, ( error, response ) => {
logger.logInfo(`${i} ${response.rowCount}`);
});
}
// IMMEDIATE
// with an occasional empty result
helper.query(`SELECT now(), $1, $2::INT WHERE $2::INT % 1000 != 0`, [ { abc: true }, ~~i ], ( error, response ) => {
logger.logInfo(`${i} ${response.rowCount}`);
if ( response.rowCount === 0 ) logger.logError(new Error('generic error text'));
});
if ( i % 400 === 0 ) {
// IMMEDIATE + ERROR
// quick fail with params
helper.query(`SELECT now(), $1, $2, AND AND`, [ { abc: true }, i ], ( error, response ) => {
logger.logInfo(`${i} ${response.rowCount}`);
});
}
}
}); All the functions in here do what you would expect
PS - it's worth noting this and #1105 occur occasionally together (but not always). Either way has the same root cause of a null |
@charmander: I got a consistent repro of this bug in our tests (on let pg = require('pg');
// FWIW `new pg.Client(process.env.DATABASE_URL)` and `.connect()` will also repro the bug
var pool = new pg.Pool({
connectionString: process.env.DATABASE_URL,
idleTimeoutMillis: 0
});
// this can be pretty much any query
let sql = `SELECT * FROM pg_catalog.pg_tables WHERE schemaname = 'public'`;
pool.query(sql, [], function() {
// throw an error in the callback of the first query
throw new Error('test');
});
setTimeout(function() {
// the next query will fail with `Cannot read property 'handleRowDescription' of null`
// because `this.activeQuery` is null
pool.query(sql);
}, 500);
// an uncaughtException handler (which mocha & other assert-driven test frameworks use)
// is necessary so the process doesn't exit after the first error
process.on('uncaughtException', err => {
console.error(`Uncaught Error: ${err.message}`);
}); Note that I also got the #1105 error once, but every other time I got |
@prust Thanks for putting that together. Resuming after |
I forgot to mention I ended up narrowing down to the same reproduction @prust shows here and solved it (at least locally in my own project) by wrapping the callback in a try-catch before moving on function runQuery ( sql, values, _cb ) {
function cb ( ...args ) {
try {
return _cb(...args);
}
catch (e) {
console.error(e);
}
}
return pool.query(sql, values, cb);
} ^ for those needing a quicker workaround |
@dhenson02: Thanks! One downside of this workaround is that it has the side effect of making errors less visible (though they are still be emitted to stderr). This is particularly bad in the context of a test suite, where you want errors to be detected and reported by the test framework (mocha, jest, etc). Your workaround can be modified so that the test framework still detects the error by running the callback in a function runQuery ( sql, values, _cb ) {
function cb ( ...args ) {
process.nextTick(function() {
_cb(...args);
});
}
return pool.query(sql, values, cb);
}
It isn't normal in a production context, but it is normal in a testing context (mocha does this and I believe jest does as well).
I do think this will go away once everyone migrates away from callbacks, but for large, feature-complete codebases, that migration may take a long time or may never make sense from a cost/benefit perspective. IMO, it would be better if node-postgres did the necessary cleanup regardless of an exception being thrown in the callback. This could be done by catching the error and re-throwing it after the cleanup is done, or by calling the callback in a |
…rors from interfering with cleanup
Hi.
We have updated our set up from
nodejs 14.4.0
Ubuntu 18.04.4 LTS
psql (PostgreSQL) 12.1
pg 8.2.1
to:
nodejs 16.1.0
Ubuntu 20.04.2 LTS
psql (PostgreSQL) 12.6
pg 8.6
After that, the pg connection started crashing.
Before the update, our code had been working properly for several years.
The error is floating. The error can appear several times a day, or maybe after a few days (7-8).
2021-05-29T09:42:16.192Z TypeError: Cannot read property 'handleRowDescription' of null
at Client._handleRowDescription (/home/user_name/node_modules/pg/lib/client.js:340:22)
at Connection.emit (node:events:365:28)
at Connection.emit (node:domain:470:12)
at /home/user_name/node_modules/pg/lib/connection.js:114:12
at Parser.parse (/home/user_name/node_modules/pg-protocol/dist/parser.js:40:17)
at Socket. (/home/user_name/node_modules/pg-protocol/dist/index.js:11:42)
at Socket.emit (node:events:365:28)
at Socket.emit (node:domain:470:12)
at addChunk (node:internal/streams/readable:314:12)
at readableAddChunk (node:internal/streams/readable:289:9) TypeError: Cannot read property 'handleRowDescription' of null
at Client._handleRowDescription (/home/user_name/node_modules/pg/lib/client.js:340:22)
at Connection.emit (node:events:365:28)
at Connection.emit (node:domain:470:12)
at /home/user_name/node_modules/pg/lib/connection.js:114:12
at Parser.parse (/home/user_name/node_modules/pg-protocol/dist/parser.js:40:17)
at Socket. (/home/user_name/node_modules/pg-protocol/dist/index.js:11:42)
at Socket.emit (node:events:365:28)
at Socket.emit (node:domain:470:12)
at addChunk (node:internal/streams/readable:314:12)
at readableAddChunk (node:internal/streams/readable:289:9)
Any advice?
The text was updated successfully, but these errors were encountered: