sequelize: FindOrCreate concurrent update error with Postgres

Hi guys, I’m using the sequelize version 2.0.0-rc1 with postgres. My project receive third party notifications on invoices and try to update or create the invoice if it doesn’t exists. Sometimes I receive simultaneous notifications about the same invoice (e.g.: for trial invoice, open + close) which sometime end up with this error :

SequelizeDatabaseError: error: could not serialize access due to concurrent update
        at module.exports.Query.formatError (/var/www/my_project/node_modules/sequelize/lib/dialects/postgres/query.js:248:16)
        at null.<anonymous> (/var/www/my_project/node_modules/sequelize/lib/dialects/postgres/query.js:65:21)
        at EventEmitter.emit (events.js:95:17)
        at Query.handleError (/var/www/my_project/node_modules/pg/lib/query.js:101:8)
        at null.<anonymous> (/var/www/my_project/node_modules/pg/lib/client.js:167:26)
        at EventEmitter.emit (events.js:95:17)
        at Socket.<anonymous> (/var/www/my_project/node_modules/pg/lib/connection.js:109:12)
        at Socket.EventEmitter.emit (events.js:95:17)
        at Socket.<anonymous> (_stream_readable.js:746:14)
        at Socket.EventEmitter.emit (events.js:92:17)

I could bind this error on transaction thanks to this explanation : http://stackoverflow.com/questions/7705273/what-are-the-conditions-for-encountering-a-serialization-failure

But still not sure on how to fix this.

About this issue

  • Original URL
  • State: closed
  • Created 10 years ago
  • Comments: 18 (6 by maintainers)

Most upvoted comments

Is there a solution for this? I’m encountering this with 3.29.0.