node-postgres
node-postgres copied to clipboard
Cursor crash when reaching query_timeout
When query with cursor, following code will crash.
import { Pool, PoolClient, escapeIdentifier } from 'pg';
import Cursor from 'pg-cursor';
const dbConfig = parse('postgresql://postgres@localhost/postgres');
const pgPool = new Pool({
host: dbConfig.host,
port: Number(dbConfig.port),
user: dbConfig.user,
database: dbConfig.database,
max: 10,
idleTimeoutMillis: 30000,
statement_timeout: 3000,
connectionTimeoutMillis: 3000,
});
let client = await pgPool.connect();
console.log(`client-${id} connected`);
client.on('error', (err) => {
console.error(`client error: ${err}`);
});
client.on('end', () => {
console.log(`client end`);
});
const cursor = client.query(new Cursor('select 1'));
await new Promise(resolve=>setTimeout(resolve, 5000));
<path-to-my-project>\node_modules\pg\lib\client.js:561
queryCallback(error)
^
source-map-support.js:722
TypeError: queryCallback is not a function
at Timeout._onTimeout (<path-to-my-project>\node_modules\pg\lib\client.js:561:9)
at listOnTimeout (node:internal/timers:569:17)
at processTimers (node:internal/timers:512:7)
source-map-support.js:726
Process exited with code 1
source code that throws: https://github.com/brianc/node-postgres/blob/26ace0ac8f1bbf0a9ac26025a36ab15e4c6fa4af/packages/pg/lib/client.js#L551-L562
The code may seem wired, because I'm trying to make my program robust by testing all cases that will throw, and finding auto recover methods.