Baike.dev
All toolsAI codingTrendingOpen sourceNewsSubmit
Log in
Back to tool/Back to issues
#3768·node-postgres

Does pg-cursor return empty result even on network error?

Author: ackavaCreated Sep 7, 2026Updated Sep 7, 2026

As per this link https://node-postgres.com/apis/cursor , cursor will return empty result so we can stop.

But we have found that under huge load, when postgres closes connection or throws an error due to deadlock, cursor returns empty result. This happens rarely and out of 100 thousand of transactions, approx 20 to 80 transactions fail when cursor returns empty results, but results are sure there.

This occurs only under huge load. Under moderate or low load, everything works fine.

javascript
    async *next(min = 100) {

        const connection = await this.connection.getConnection(this.signal);
        const q = toQuery(this.command);
        const cursor = this.cursor = connection.query(new Cursor(q.text, q.values));
        do {
            const rows = await cursor.read(min);
            yield *rows;
            if (rows.length === 0) {
                break;
            }
        } while (true);
    }

Do I need to add error handler here as well?

Unfortunately I cannot create a stressed environment that results in similar situation.

Source: brianc/node-postgres

View original on GitHubView discussion on GitHub