HangfireIO / HangfireIO/Hangfire
[bug] Npgsql: A command is already in progress.
- Dominant language
- C#
- Stars
- 10.1k
- Forks
- 1.8k
- Avg merge
- 1h 19m
- Merged PRs (30d)
- 1
Description
some time throws an exception
Npgsql.NpgsqlOperationInProgressException
A command is already in progress:
```
WITH "inputvalues" AS ( SELECT @key "key", @field "field", @value "value" ), "updatedrows" AS ( UPDATE "hangfire"."hash" "updatetarget" SET "value" = "inputvalues"."value" FROM "inputvalues" WHERE "updatetarget"."key" = "inputvalues"."key" AND "updatetarget"."field" = "inputvalues"."field" RETURNING "updatetarget"."key", "updatetarget"."field" ) INSERT INTO "hangfire"."hash"("key", "field", "value") SELECT "key", "field", "value" FROM "inputvalues" "insertvalues" WHERE NOT EXISTS ( SELECT 1 FROM "updatedrows" WHERE "updatedrows"."key" = "insertvalues"."key" AND "updatedrows"."field" = "insertvalues"."field" );
Npgsql.NpgsqlOperationInProgressException: A command is already in progress:
WITH "inputvalues" AS (
SELECT @key "key", @field "field", @value "value"
), "updatedrows" AS (
UPDATE "hangfire"."hash" "updatetarget"
SET "value" = "inputvalues"."value"
FROM "inputvalues"
WHERE "updatetarget"."key" = "inputvalues"."key"
AND "updatetarget"."field" = "inputvalues"."field"
RETURNING "updatetarget"."key", "updatetarget"."field"
)
INSERT INTO "hangfire"."hash"("key", "field", "value")
SELECT "key", "field", "value"
FROM "inputvalues" "insertvalues"
WHERE NOT EXISTS (
SELECT 1
FROM "updatedrows"
WHERE "updatedrows"."key" = "insertvalues"."key"
AND "updatedrows"."field" = "insertvalues"."field"
);
```
```
at Npgsql.NpgsqlConnector.g__DoStartUserAction|186_0(<>c__DisplayClass186_0& )
at Npgsql.NpgsqlConnector.StartUserAction(ConnectorState newState, NpgsqlCommand command)
at Npgsql.NpgsqlCommand.ExecuteDbDataReader(CommandBehavior behavior, Boolean async, CancellationToken cancellationToken)
at Npgsql.NpgsqlCommand.ExecuteDbDataReader(CommandBehavior behavior)
at System.Data.Common.DbCommand.System.Data.IDbCommand.ExecuteReader(CommandBehavior behavior)
at Dapper.SqlMapper.ExecuteReaderWithFlagsFallback(IDbCommand cmd, Boolean wasClosed, CommandBehavior behavior) in C:\projects\dapper\Dapper\SqlMapper.cs:line 1053
at Dapper.SqlMapper.QueryImpl[T](IDbConnection cnn, CommandDefinition command, Type effectiveType)+MoveNext() in C:\projects\dapper\Dapper\SqlMapper.cs:line 1081
at System.Collections.Generic.List`1.AddEnumerable(IEnumerable`1 enumerable)
at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
at Dapper.SqlMapper.Query[T](IDbConnection cnn, String sql, Object param, IDbTransaction transaction, Boolean buffered, Nullable`1 commandTimeout, Nullable`1 commandType) in C:\projects\dapper\Dapper\SqlMapper.cs:line 723
at Hangfire.PostgreSql.PostgreSqlConnection.GetHashTtl(String key)
at Hangfire.Console.Server.ConsoleContext.FixExpiration()
at Hangfire.Console.Server.ConsoleServerFilter.OnPerformed(PerformedContext filterContext)
at Hangfire.Profiling.ProfilerExtensions.InvokeAction[TInstance](InstanceAction`1 tuple)
at Hangfire.Profiling.SlowLogProfiler.InvokeMeasured[TInstance,TResult](TInstance instance, Func`2 action, String message)
at Hangfire.Profiling.ProfilerExtensions.InvokeMeasured[TInstance](IProfiler profiler, TInstance instance, Action`1 action, String message)
at Hangfire.Server.BackgroundJobPerformer.InvokePerformFilter(IServerFilter filter, PerformingContext preContext, Func`1 continuation)
```
Contributor guide
Research direction
Start at Hangfire.PostgreSql.PostgreSqlConnection.GetHashTtl and the Hangfire.Console.Server.ConsoleContext.FixExpiration call shown in the stack trace. Reproduce the reported PostgreSQL operation-in-progress failure under the console expiration path, then trace the connection and command lifetime through the Dapper query. Done means the reported path no longer raises NpgsqlOperationInProgressException and has regression coverage.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp, postgresql
- Domain
- backend, database
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 28/100