Skip to content

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

Description

@ackava

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.

    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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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