A concurrent duplicate write on a relational engine answers 409, not 500 #311

Closed
opened 2026-11-05 13:30:23 -05:00 by claude · 0 comments
Owner
  • Priority: low
  • Agent: storage-coder
  • Depends on: #60
  • Decisions: none

Why

On SQLite, PostgreSQL, MySQL and SQL Server a write that breaks a unique index surfaces as a 500. The controllers check for a duplicate first and answer 409 with ConflictException, but two concurrent writes both pass the check, and the second fails inside SaveChanges with a DbUpdateException. Nothing in src maps it (NinlilExceptionHandler maps only the Ninlil exception types). Examples: the unique indexes on DHCP custom options in src/dotnet/src/Ninlil.Dns.Data.EntityFrameworkCore/Configuration/DhcpScopeCustomOptionConfiguration.cs:39-40 and DhcpTagRuleOptionConfiguration.cs:36-37; the controller comments in DhcpScopeCustomOptionsController.cs:204-209 and DhcpTagRuleOptionsController.cs:197-202 describe the 500.

#60 maps MongoDB's duplicate-key error (11000) to ConflictException in MongoChangeTracker.FlushAsync, so MongoDB answers 409 for the same race.

What changes

  • In the EF Core unit of work (Ninlil.Dns.Data.EntityFrameworkCore), map a DbUpdateException caused by a unique-constraint violation to ConflictException, for each provider (SQLite SQLITE_CONSTRAINT_UNIQUE 2067 / primary key 1555, PostgreSQL SQLSTATE 23505, MySQL 1062, SQL Server 2601 and 2627). Log the original error before rethrowing. Leave other DbUpdateExceptions as they are.
  • Update the two controller comments.

Acceptance

  • src/dotnet/tests/Ninlil.Dns.Data.Integration.Tests: on every relational engine, a second insert of the same DHCP option tag on one scope that bypasses the controller's pre-check throws ConflictException (fails on HEAD). SQLite without Docker; the others with the RequiresDocker trait.
  • A non-unique DbUpdateException (for example a foreign-key violation) is not turned into a conflict.

Source

Verifier report on #60 (feature/60-mongo-dhcp-option-unique).

- **Priority:** low - **Agent:** storage-coder - **Depends on:** #60 - **Decisions:** none ### Why On SQLite, PostgreSQL, MySQL and SQL Server a write that breaks a unique index surfaces as a 500. The controllers check for a duplicate first and answer 409 with `ConflictException`, but two concurrent writes both pass the check, and the second fails inside `SaveChanges` with a `DbUpdateException`. Nothing in `src` maps it (`NinlilExceptionHandler` maps only the Ninlil exception types). Examples: the unique indexes on DHCP custom options in `src/dotnet/src/Ninlil.Dns.Data.EntityFrameworkCore/Configuration/DhcpScopeCustomOptionConfiguration.cs:39-40` and `DhcpTagRuleOptionConfiguration.cs:36-37`; the controller comments in `DhcpScopeCustomOptionsController.cs:204-209` and `DhcpTagRuleOptionsController.cs:197-202` describe the 500. #60 maps MongoDB's duplicate-key error (11000) to `ConflictException` in `MongoChangeTracker.FlushAsync`, so MongoDB answers 409 for the same race. ### What changes - In the EF Core unit of work (`Ninlil.Dns.Data.EntityFrameworkCore`), map a `DbUpdateException` caused by a unique-constraint violation to `ConflictException`, for each provider (SQLite `SQLITE_CONSTRAINT_UNIQUE` 2067 / primary key 1555, PostgreSQL SQLSTATE 23505, MySQL 1062, SQL Server 2601 and 2627). Log the original error before rethrowing. Leave other `DbUpdateException`s as they are. - Update the two controller comments. ### Acceptance - [ ] `src/dotnet/tests/Ninlil.Dns.Data.Integration.Tests`: on every relational engine, a second insert of the same DHCP option tag on one scope that bypasses the controller's pre-check throws `ConflictException` (fails on HEAD). SQLite without Docker; the others with the `RequiresDocker` trait. - [ ] A non-unique `DbUpdateException` (for example a foreign-key violation) is not turned into a conflict. ### Source Verifier report on #60 (`feature/60-mongo-dhcp-option-unique`).
Sign in to join this conversation.
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
lantea-one/ninlil#311
No description provided.