I am trying to understand the test case https://github.com/sequelize/sequelize/blob/main/test/integration/model/create.test.js
it('should not deadlock with concurrency duplicate entries and no outer transaction',
Basically a function , findOrCreate is called 50times , each returns a promise. findOrCreate function opens a transaction, does a select call and a row is inserted if row not found. I had the following query on how its implemented in https://github.com/brianc/node-postgres
- findOrCreate has following sqls to run; start txn, select, insert, commit txn. as part of insert an exclusive lock must be taken on that row which is released only after running sql "commit txn". If multiple calls to findOrCreate happen, one of the instance can again run the above sqls and when running query "insert" it should hang(even loop block) because the callback for commit txn from first instance has not yet been called.
From traces, I always see somehow the second instance insert never happens before the first commit. Is this just by luck? Please help me understand. Does node-postgres use some kind of events instead of just blocking on exclusive lock?