Duplicate key violation
See original GitHub issueDescribe the bug
When running multiple API instances in parallel, race conditions occur in the assignToChannels
function throwing duplicate key violation errors.
To Reproduce Steps to reproduce the behavior:
- Run 2 API instances
- Create a Product on 1 API instance
- Simultaneously add a different ProductVariant to the Product on each API instance
- Sometimes the error will occur
Expected behavior The check and insert in the database should be an atomic operation
Environment (please complete the following information):
- @vendure/core version: 1.0.2
- Nodejs version: 14
- Database: postgres
Issue Analytics
- State:
- Created 2 years ago
- Comments:7 (7 by maintainers)
Top Results From Across the Web
Violation of PRIMARY KEY constraint. Cannot insert duplicate ...
Cannot insert duplicate key in object 'dbo. AC_Shipping_Addresses'. The duplicate key value is (165863).
Read more >Hidden dangers of duplicate key violations in PostgreSQL and ...
The “duplicate key violates unique constraint” error notifies the caller that a retry is needed. This seems like an intuitive approach, ...
Read more >How to solve violation of PRIMARY KEY constraint ...
If the key is an identity column it shouldn't cause duplicates unless someone has reseeded the counter. In such case reseeding the counter...
Read more >Error "Violation of PRIMARY KEY constraint. Cannot insert ...
1. Duplicate the Selection you are working on - then start working on the copied Selection · 2. Create an In Filter and...
Read more >Violation of PRIMARY KEY constraint - Microsoft Q&A
Violation of PRIMARY KEY constraint ... Cannot insert duplicate key in object 'dbo.Staff'. The duplicate key value is (42840)' error.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
https://github.com/typeorm/typeorm/issues/1090#issuecomment-634391487 might hold the solution to this issue
Hi Michael, it’s been a while and we have not encountered this error recently and thus have not been able to provide you with more details. However the problem still exists as far as we know. Reading the blogpost on the release of Vendure 1.3, the new with transaction() reminded me of this issue. This might be the perfect occasion for it? If needed I can try to plan in some time to create a repo that reproduces this issue.