Skip to content

Cursor crash when reaching query_timeout #3475

Open
@hwc0919

Description

@hwc0919

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:

if (readTimeout) {
queryCallback = query.callback
readTimeoutTimer = setTimeout(() => {
const error = new Error('Query read timeout')
process.nextTick(() => {
query.handleError(error, this.connection)
})
queryCallback(error)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions