Skip to content

pg-cursor timeouts #2183

Description

@alesmenzel

Hi, I think this is a bug within the pg-cursor library. I believe that when the operation between reading from the cursor takes more than X s, the cursor times out.

Here is the error I am getting:

error: canceling statement due to statement timeout
    at Connection.parseE (<path>/node_modules/pg/lib/connection.js:614:13)
    at Connection.parseMessage (<path>/node_modules/pg/lib/connection.js:413:19)
    at TLSSocket.<anonymous> (<path>/node_modules/pg/lib/connection.js:129:22)
    at TLSSocket.emit (events.js:321:20)
    at addChunk (_stream_readable.js:294:12)
    at readableAddChunk (_stream_readable.js:275:11)
    at TLSSocket.Readable.push (_stream_readable.js:209:10)
    at TLSWrap.onStreamRead (internal/stream_base_commons.js:186:23) {
  name: 'error',
  length: 109,
  severity: 'ERROR',
  code: '57014',
  detail: undefined,
  hint: undefined,
  position: undefined,
  internalPosition: undefined,
  internalQuery: undefined,
  where: undefined,
  schema: undefined,
  table: undefined,
  column: undefined,
  dataType: undefined,
  constraint: undefined,
  file: 'postgres.c',
  line: '2985',
  routine: 'ProcessInterrupts'
}

This is a pseudo reproduction code:

async function * Iterator () {
  const cursor = await client.query(new Cursor(query, replacements))
  const cursorP = {
    read: util.promisify(cursor.read).bind(cursor),
    close: util.promisify(cursor.close).bind(cursor),
  }
  while (true) {
    const rows = await cursorP.read(size)
    if (!rows.length) {
      await cursorP.close()
      client.release()
      return
    }
    yield rows
  }
}

const iterable = await Iterator()
for await (const x of iterable) {
  // do stuff
  await doStomething(x);
}

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