Skip to content

Accounting Service drops "duplicate key value violates" #2783

@svrnm

Description

@svrnm

Bug Report

I was running the otel demo for a longer time and at some point the accounting service started to drop duplicate key value violates

Reproduce

I am still investigating why this is happening but my feeling is that this happens by running the service for a long time ("hours").

Additional Context

Log Entry

│ info: Accounting.Consumer[174880625]                                                                                                                                                                                                                                                                             │
│       Order details: { "orderId": "5fbce811-cf5a-11f0-8ab4-d61ef845fff7", "shippingTrackingId": "ea236d83-469e-42fd-b205-2303aeedcc96", "shippingCost": { "currencyCode": "USD", "units": "231" }, "shippingAddress": { "streetAddress": "100 Winchester Circle", "city": "Los Gatos", "state": "CA", "country": │
│  "United States", "zipCode": "95032" }, "items": [ { "item": { "productId": "2ZYFJ3GM2N", "quantity": 5 }, "cost": { "currencyCode": "USD", "units": "209", "nanos": 949999999 } } ] }.                                                                                                                          │
│ fail: Accounting.Consumer[0]                                                                                                                                                                                                                                                                                     │
│       Order parsing failed:                                                                                                                                                                                                                                                                                      │
│       Microsoft.EntityFrameworkCore.DbUpdateException: An error occurred while saving the entity changes. See the inner exception for details.                                                                                                                                                                   │
│        ---> Npgsql.PostgresException (0x80004005): 23505: duplicate key value violates unique constraint "order_pkey"                                                                                                                                                                                            │
│                                                                                                                                                                                                                                                                                                                  │
│       DETAIL: Detail redacted as it may contain sensitive data. Specify 'Include Error Detail' in the connection string to include this information.                                                                                                                                                             │
│          at Npgsql.Internal.NpgsqlConnector.ReadMessageLong(Boolean async, DataRowLoadingMode dataRowLoadingMode, Boolean readingNotifications, Boolean isReadingPrependedMessage)                                                                                                                               │
│          at System.Runtime.CompilerServices.PoolingAsyncValueTaskMethodBuilder`1.StateMachineBox`1.System.Threading.Tasks.Sources.IValueTaskSource<TResult>.GetResult(Int16 token)                                                                                                                               │
│          at Npgsql.NpgsqlDataReader.NextResult(Boolean async, Boolean isConsuming, CancellationToken cancellationToken)                                                                                                                                                                                          │
│          at Npgsql.NpgsqlDataReader.NextResult(Boolean async, Boolean isConsuming, CancellationToken cancellationToken)                                                                                                                                                                                          │
│          at Npgsql.NpgsqlDataReader.NextResult()                                                                                                                                                                                                                                                                 │
│          at Npgsql.NpgsqlCommand.ExecuteReader(Boolean async, CommandBehavior behavior, CancellationToken cancellationToken)                                                                                                                                                                                     │
│          at Npgsql.NpgsqlCommand.ExecuteReader(Boolean async, CommandBehavior behavior, CancellationToken cancellationToken)                                                                                                                                                                                     │
│          at Npgsql.NpgsqlCommand.ExecuteReader(CommandBehavior behavior)                                                                                                                                                                                                                                         │
│          at Npgsql.NpgsqlCommand.ExecuteDbDataReader(CommandBehavior behavior)                                                                                                                                                                                                                                   │
│          at System.Data.Common.DbCommand.ExecuteReader()                                                                                                                                                                                                                                                         │
│          at Microsoft.EntityFrameworkCore.Storage.RelationalCommand.ExecuteReader(RelationalCommandParameterObject parameterObject)                                                                                                                                                                              │
│          at Microsoft.EntityFrameworkCore.Update.ReaderModificationCommandBatch.Execute(IRelationalConnection connection)                                                                                                                                                                                        │
│         Exception data:                                                                                                                                                                                                                                                                                          │
│           Severity: ERROR                                                                                                                                                                                                                                                                                        │
│           SqlState: 23505                                                                                                                                                                                                                                                                                        │
│           MessageText: duplicate key value violates unique constraint "order_pkey"                                                                                                                                                                                                                               │
│           Detail: Detail redacted as it may contain sensitive data. Specify 'Include Error Detail' in the connection string to include this information.                                                                                                                                                         │
│           SchemaName: public                                                                                                                                                                                                                                                                                     │
│           TableName: order                                                                                                                                                                                                                                                                                       │
│           ConstraintName: order_pkey                                                                                                                                                                                                                                                                             │
│           File: nbtinsert.c                                                                                                                                                                                                                                                                                      │
│           Line: 666                                                                                                                                                                                                                                                                                              │
│           Routine: _bt_check_unique                                                                                                                                                                                                                                                                              │
│          --- End of inner exception stack trace ---                                                                                                                                                                                                                                                              │
│          at Microsoft.EntityFrameworkCore.Update.ReaderModificationCommandBatch.Execute(IRelationalConnection connection)                                                                                                                                                                                        │
│          at Microsoft.EntityFrameworkCore.Update.Internal.BatchExecutor.Execute(IEnumerable`1 commandBatches, IRelationalConnection connection)                                                                                                                                                                  │
│          at Microsoft.EntityFrameworkCore.Storage.RelationalDatabase.SaveChanges(IList`1 entries)                                                                                                                                                                                                                │
│          at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.StateManager.SaveChanges(IList`1 entriesToSave)                                                                                                                                                                                                │
│          at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.StateManager.SaveChanges(StateManager stateManager, Boolean acceptAllChangesOnSuccess)                                                                                                                                                         │
│          at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.StateManager.<>c.<SaveChanges>b__112_0(DbContext _, ValueTuple`2 t)                                                                                                                                                                            │
│          at Npgsql.EntityFrameworkCore.PostgreSQL.Storage.Internal.NpgsqlExecutionStrategy.Execute[TState,TResult](TState state, Func`3 operation, Func`3 verifySucceeded)                                                                                                                                       │
│          at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.StateManager.SaveChanges(Boolean acceptAllChangesOnSuccess)                                                                                                                                                                                    │
│          at Microsoft.EntityFrameworkCore.DbContext.SaveChanges(Boolean acceptAllChangesOnSuccess)                                                                                                                                                                                                               │
│          at Microsoft.EntityFrameworkCore.DbContext.SaveChanges()                                                                                                                                                                                                                                                │
│          at Accounting.Consumer.ProcessMessage(Message`2 message) in /src/Accounting/Consumer.cs:line 125                                                                                                                                                                                                        │
│ info: Accounting.Consumer[174880625]                                                                                                                                                                                                                                                                             │
│       Order details: { "orderId": "602832be-cf5a-11f0-8ab4-d61ef845fff7", "shippingTrackingId": "10830fa5-87ae-4563-a897-dd45c1d53952", "shippingCost": { "currencyCode": "CAD", "units": "128", "nanos": 464219371 }, "shippingAddress": { "streetAddress": "150 Elgin St", "city": "Ottawa", "state": "ON", "c │
│ ountry": "Canada", "zipCode": "K2P1L4" }, "items": [ { "item": { "productId": "1YMWWN1N4O", "quantity": 1 }, "cost": { "currencyCode": "CAD", "units": "173", "nanos": 895055285 } } ] }.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions