Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Retry failing for implicit pool queries #176

@ivank

Description

@ivank

When using pool.query and Postgres throws an error, for example deadlock detected, code 40P01 slink attempts a retry. It is possible to have a deadlock even when executing a normal update query, not just a transaction.

Expected Behavior

We should retry the implicit query.

Current Behavior

The query mechanism seems to assume there are transactionQueries and we end up with transactionQueries is not iterable error. (In node_modules/slonik/dist/routines/executeQuery.js:32:38)

Steps to Reproduce

Execute several update queries that would deadlock, using implicit pool.query

Logs

    TypeError: transactionQueries is not iterable
        at retryTransaction (/Users/ivankerin/Projects/boost-statements-loss/node_modules/slonik/dist/routines/executeQuery.js:32:38)
        at process._tickCallback (internal/process/next_tick.js:68:7) }

If I set transactionRetryLimit: 0, I get:

   error:
    { error: deadlock detected
        at Connection.parseE (/Users/ivankerin/Projects/boost-statements-loss/node_modules/pg/lib/connection.js:614:13)
        at Connection.parseMessage (/Users/ivankerin/Projects/boost-statements-loss/node_modules/pg/lib/connection.js:413:19)
        at Socket.<anonymous> (/Users/ivankerin/Projects/boost-statements-loss/node_modules/pg/lib/connection.js:129:22)
        at Socket.emit (events.js:198:13)
        at Socket.EventEmitter.emit (domain.js:448:20)
        at addChunk (_stream_readable.js:287:12)
        at readableAddChunk (_stream_readable.js:268:11)
        at Socket.Readable.push (_stream_readable.js:223:10)
        at TCP.onStreamRead [as onread] (internal/stream_base_commons.js:94:17)
      name: 'error',
      length: 323,
      severity: 'ERROR',
      code: '40P01',
      detail:
       'Process 383 waits for ShareLock on transaction 5191; blocked by process 378.\nProcess 378 waits for ShareLock on transaction 5190; blocked by process 383.',
      hint: 'See server log for query details.',
      position: undefined,
      internalPosition: undefined,
      internalQuery: undefined,
      where: 'while updating tuple (59565,14) in relation "supply"',
      schema: undefined,
      table: undefined,
      column: undefined,
      dataType: undefined,
      constraint: undefined,
      file: 'deadlock.c',
      line: '1146',
      routine: 'DeadLockReport' } }

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions