HangfireIO / HangfireIO/Hangfire
Unique constraint error in Hangfire
- Dominant language
- C#
- Stars
- 10.1k
- Forks
- 1.8k
- Avg merge
- 1h 19m
- Merged PRs (30d)
- 1
Description
The below mentioned error is thrown when calling `AddOrUpdate` method in `IRecurringJobManager` interface in Hangfire.
`23505: duplicate key value violates unique constraint "hash_pkey" DETAIL: Detail redacted as it may contain sensitive data. Specify 'Include Error Detail' in the connection string to include this information.`
`Npgsql.PostgresException
at Npgsql.Internal.NpgsqlConnector.g__ReadMessageLong|215_0(NpgsqlConnector connector, Boolean async, DataRowLoadingMode dataRowLoadingMode, Boolean readingNotifications, Boolean isReadingPrependedMessage)
at Npgsql.NpgsqlDataReader.NextResult(Boolean async, Boolean isConsuming, CancellationToken cancellationToken)
at Npgsql.NpgsqlDataReader.NextResult()
at Npgsql.NpgsqlCommand.ExecuteReader(CommandBehavior behavior, Boolean async, CancellationToken cancellationToken)
at Npgsql.NpgsqlCommand.ExecuteReader(CommandBehavior behavior, Boolean async, CancellationToken cancellationToken)
at Npgsql.NpgsqlCommand.ExecuteNonQuery(Boolean async, CancellationToken cancellationToken)
at Npgsql.NpgsqlCommand.ExecuteNonQuery()
at Dapper.SqlMapper.ExecuteCommand(IDbConnection cnn, CommandDefinition& command, Action 2 paramReader) in C:\projects\dapper\Dapper\SqlMapper.cs:line 2836
at Dapper.SqlMapper.ExecuteImpl(IDbConnection cnn, CommandDefinition& command) in C:\projects\dapper\Dapper\SqlMapper.cs:line 570
at Hangfire.PostgreSql.PostgreSqlWriteOnlyTransaction.<>c__DisplayClass23_1.b__0(NpgsqlConnection con)
at Hangfire.PostgreSql.PostgreSqlWriteOnlyTransaction.Commit()
at Hangfire.RecurringJobManager.AddOrUpdate(String recurringJobId, Job job, String cronExpression, RecurringJobOptions options)
at UpdateReportSchedule(UserToken user, Guid reportConfigGuid, ReadershipReportConfigDto job) in /Services/ScheduleService.cs:line 109`
Does anyone know why this happens and how to fix this?
Contributor guide
Research direction
Begin with IRecurringJobManager.AddOrUpdate and the call at /Services/ScheduleService.cs:109, then reproduce the PostgreSQL 23505 error and inspect the Hangfire.PostgreSql transaction stack. Compare the recurring-job ID and concurrent calls involved; done means the cause is isolated and a verified fix or minimal reproduction is documented.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp, postgresql
- Domain
- backend, databases
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100