Hangfire.Redis.StackExchange icon indicating copy to clipboard operation
Hangfire.Redis.StackExchange copied to clipboard

"A null value is not valid in this context" exception occurs as Hangfire attempts to execute a scheduled job.

Open lujiaxing opened this issue 10 months ago • 3 comments

"System.ArgumentException: A null value is not valid in this context" exception occurs as Hangfire attempts to execute a scheduled job.

It appears that when creating a new scheduled job, the "Queue" property of the job serialization entity Hangfire.Common.Job never gets a value. However, when the BackgroundJobFactory attempts to read a scheduled task and convert it to a job and save it as a redis "Hash" value, StackExchange.Redis will check if each item is null. Consequently, the constant null-value property "Queue" triggers the exception in StackExchange.Redis without a surprise.

image

Here is how i add a scheduled job:

RecurringJob.AddOrUpdate("test", 
    () => someInstance.DoSomething("abcd", 1234),
    "0 */1 * * * ?");
An exception occurred while creating a background job, see inner exception for details.
System.ArgumentException: A null value is not valid in this context
   at StackExchange.Redis.RedisValue.AssertNotNull() in /_/src/StackExchange.Redis/RedisValue.cs:line 308
   at StackExchange.Redis.Message.CommandKeyValuesMessage..ctor(Int32 db, CommandFlags flags, RedisCommand command, RedisKey& key, RedisValue[] values) in /_/src/StackExchange.Redis/Message.cs:line 1050
   at StackExchange.Redis.Message.Create(Int32 db, CommandFlags flags, RedisCommand command, RedisKey& key, RedisValue[] values) in /_/src/StackExchange.Redis/Message.cs:line 426
   at StackExchange.Redis.RedisDatabase.GetHashSetMessage(RedisKey key, HashEntry[] hashFields, CommandFlags flags) in /_/src/StackExchange.Redis/RedisDatabase.cs:line 3422
   at StackExchange.Redis.RedisDatabase.HashSetAsync(RedisKey key, HashEntry[] hashFields, CommandFlags flags) in /_/src/StackExchange.Redis/RedisDatabase.cs:line 589
   at Hangfire.Redis.StackExchange.RedisConnection.CreateExpiredJob(Job job, IDictionary`2 parameters, DateTime createdAt, TimeSpan expireIn) in F:\src\Hangfire.Redis.StackExchange\Hangfire.Redis.StackExchange\RedisCo
nnection.cs:line 165
   at Hangfire.Client.CoreBackgroundJobFactory.<>c__DisplayClass15_0.<CreateBackgroundJobTwoSteps>b__0(Int32 _) in C:\projects\hangfire-525\src\Hangfire.Core\Client\CoreBackgroundJobFactory.cs:line 87
   at Hangfire.Client.CoreBackgroundJobFactory.RetryOnException[T](Int32& attemptsLeft, Func`2 action) in C:\projects\hangfire-525\src\Hangfire.Core\Client\CoreBackgroundJobFactory.cs:line 164
fail: Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware[1]
An unhandled exception has occurred while executing the request.
System.ArgumentException: A null value is not valid in this context
   at StackExchange.Redis.RedisValue.AssertNotNull() in /_/src/StackExchange.Redis/RedisValue.cs:line 308
   at StackExchange.Redis.Message.CommandKeyValuesMessage..ctor(Int32 db, CommandFlags flags, RedisCommand command, RedisKey& key, RedisValue[] values) in /_/src/StackExchange.Redis/Message.cs:line 1050
   at StackExchange.Redis.Message.Create(Int32 db, CommandFlags flags, RedisCommand command, RedisKey& key, RedisValue[] values) in /_/src/StackExchange.Redis/Message.cs:line 426
   at StackExchange.Redis.RedisDatabase.GetHashSetMessage(RedisKey key, HashEntry[] hashFields, CommandFlags flags) in /_/src/StackExchange.Redis/RedisDatabase.cs:line 3422
   at StackExchange.Redis.RedisDatabase.HashSetAsync(RedisKey key, HashEntry[] hashFields, CommandFlags flags) in /_/src/StackExchange.Redis/RedisDatabase.cs:line 589
   at Hangfire.Redis.StackExchange.RedisConnection.CreateExpiredJob(Job job, IDictionary`2 parameters, DateTime createdAt, TimeSpan expireIn) in F:\src\Hangfire.Redis.StackExchange\Hangfire.Redis.StackExchange\RedisCo
nnection.cs:line 165
   at Hangfire.Client.CoreBackgroundJobFactory.<>c__DisplayClass15_0.<CreateBackgroundJobTwoSteps>b__0(Int32 _) in C:\projects\hangfire-525\src\Hangfire.Core\Client\CoreBackgroundJobFactory.cs:line 87
   at Hangfire.Client.CoreBackgroundJobFactory.RetryOnException[T](Int32& attemptsLeft, Func`2 action) in C:\projects\hangfire-525\src\Hangfire.Core\Client\CoreBackgroundJobFactory.cs:line 164
--- End of stack trace from previous location ---
   at Hangfire.Client.CoreBackgroundJobFactory.RetryOnException[T](Int32& attemptsLeft, Func`2 action) in C:\projects\hangfire-525\src\Hangfire.Core\Client\CoreBackgroundJobFactory.cs:line 176
   at Hangfire.Client.CoreBackgroundJobFactory.CreateBackgroundJobTwoSteps(CreateContext context, Dictionary`2 parameters, DateTime createdAt, TimeSpan expireIn) in C:\projects\hangfire-525\src\Hangfire.Core\Client\Co
reBackgroundJobFactory.cs:line 87
   at Hangfire.Client.CoreBackgroundJobFactory.Create(CreateContext context) in C:\projects\hangfire-525\src\Hangfire.Core\Client\CoreBackgroundJobFactory.cs:line 73
   at Hangfire.Client.BackgroundJobFactory.<>c__DisplayClass12_0.<CreateWithFilters>b__0() in C:\projects\hangfire-525\src\Hangfire.Core\Client\BackgroundJobFactory.cs:line 117
   at Hangfire.Client.BackgroundJobFactory.InvokeClientFilter(IClientFilter filter, CreatingContext preContext, Func`1 continuation) in C:\projects\hangfire-525\src\Hangfire.Core\Client\BackgroundJobFactory.cs:line 14
6
   at Hangfire.Client.BackgroundJobFactory.<>c__DisplayClass12_1.<CreateWithFilters>b__2() in C:\projects\hangfire-525\src\Hangfire.Core\Client\BackgroundJobFactory.cs:line 122
   at Hangfire.Client.BackgroundJobFactory.CreateWithFilters(CreateContext context, IEnumerable`1 filters) in C:\projects\hangfire-525\src\Hangfire.Core\Client\BackgroundJobFactory.cs:line 124
   at Hangfire.Client.BackgroundJobFactory.Create(CreateContext context) in C:\projects\hangfire-525\src\Hangfire.Core\Client\BackgroundJobFactory.cs:line 84
   at Hangfire.RecurringJobExtensions.TriggerRecurringJob(IBackgroundJobFactory factory, JobStorage storage, IStorageConnection connection, IProfiler profiler, RecurringJobEntity recurringJob, DateTime now) in C:\proj
ects\hangfire-525\src\Hangfire.Core\RecurringJobExtensions.cs:line 121
   at Hangfire.RecurringJobManager.TriggerJob(String recurringJobId) in C:\projects\hangfire-525\src\Hangfire.Core\RecurringJobManager.cs:line 172
   at Hangfire.RecurringJobManager.Trigger(String recurringJobId) in C:\projects\hangfire-525\src\Hangfire.Core\RecurringJobManager.cs:line 150
   at Hangfire.Dashboard.DashboardRoutes.<>c.<.cctor>b__6_27(IRecurringJobManager manager, String jobId) in C:\projects\hangfire-525\src\Hangfire.Core\Dashboard\DashboardRoutes.cs:line 174
   at Hangfire.Dashboard.RouteCollectionExtensions.<>c__DisplayClass4_0.<AddRecurringBatchCommand>b__0(DashboardContext context, String jobId) in C:\projects\hangfire-525\src\Hangfire.Core\Dashboard\RouteCollectionExt
ensions.cs:line 115
   at Hangfire.Dashboard.BatchCommandDispatcher.Dispatch(DashboardContext context) in C:\projects\hangfire-525\src\Hangfire.Core\Dashboard\BatchCommandDispatcher.cs:line 56
   at Hangfire.Dashboard.AspNetCoreDashboardMiddleware.Invoke(HttpContext httpContext) in C:\projects\hangfire-525\src\Hangfire.AspNetCore\Dashboard\AspNetCoreDashboardMiddleware.cs:line 99
   at Microsoft.AspNetCore.Builder.Extensions.MapMiddleware.InvokeCore(HttpContext context, PathString matchedPath, PathString remainingPath)
   at ***********.Program.<>c.<<Main>b__1_7>d.MoveNext() in F:\********\Program.cs:line 145
--- End of stack trace from previous location ---
   at Swashbuckle.AspNetCore.SwaggerUI.SwaggerUIMiddleware.Invoke(HttpContext httpContext)
   at Swashbuckle.AspNetCore.Swagger.SwaggerMiddleware.Invoke(HttpContext httpContext, ISwaggerProvider swaggerProvider)
   at ***********.Program.<>c.<<Main>b__1_6>d.MoveNext() in F:\***********\Program.cs:line 118
--- End of stack trace from previous location ---
   at Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext context)
   at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context)
   at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddlewareImpl.Invoke(HttpContext context)

Package versions: Hangfire.Core/1.8.11 Hangfire.DynamicJob/0.2.0 Hangfire/1.8.11 StackExchange.Redis/2.7.33

.NET Version: .NET 8.0

OS Version: Windows 10 - 10.0.19045.4170 x64


Please try to avoid this behavior...

lujiaxing avatar Apr 01 '24 14:04 lujiaxing

This is already fixed in the current master, and will no longer be an issue in the next release. @marcoCasamento, when is the new release due?

Lexy2 avatar Apr 18 '24 22:04 Lexy2

The actual main branch is working fine on my systems for a while now, I'll try to push it to nuget this weekend

Il ven 19 apr 2024, 00:04 Lexy @.***> ha scritto:

This is already fixed in the current master, and will no longer be an issue in the next release. @marcoCasamento https://github.com/marcoCasamento, when is the new release due?

— Reply to this email directly, view it on GitHub https://github.com/marcoCasamento/Hangfire.Redis.StackExchange/issues/147#issuecomment-2065404896, or unsubscribe https://github.com/notifications/unsubscribe-auth/AABW2Y47JNMDGTQHWJWWB4DY6A7N7AVCNFSM6AAAAABFRVIX7WVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDANRVGQYDIOBZGY . You are receiving this because you were mentioned.Message ID: @.*** com>

marcoCasamento avatar Apr 19 '24 19:04 marcoCasamento

I may have found an issue with the new changes. Hold off pushing the new version for now.

Lexy2 avatar Apr 21 '24 04:04 Lexy2

@lujiaxing please test 1.9.5, it should fix your issue.

Lexy2 avatar May 06 '24 04:05 Lexy2

@lujiaxing please test 1.9.5, it should fix your issue.

The error is gone! Thanks.

lujiaxing avatar May 07 '24 01:05 lujiaxing