I have two WCF services set up to interact with Hangfire. They’re both running .NET 4.6.1 in separate but identical app pools (v4 integrated) that are set to AlwaysRunning with an idle time-out of 0, and both are configured with OwinStartup classes (Startup.cs). The only obvious difference is that one of them hosts the Hangfire server and dashboard. The “server” never seems to have any problems, but the “client” seems to lose its configuration sometime after deployment; Things work initially but later calls to BackgroundJob.Enqueue()
throw an exception (“JobStorage.Current property value has not been initialized. You must set it before using Hangfire Client or Server API.”). I’ve mitigated this by -before calling Enqueue()
- checking to see if JobStorage.Current
has been initialized, and re-running the configuration methods if it hasn’t, but that’s a bit of a hack. What do I need to do to make sure that the “client” doesn’t keep losing its Hangfire configuration?
We had this problem also for the first time over the weekend on our production webserver. Without any restart, the server suddenly lost if configuration and started throwing the error you described. An IIS reset put it back online. We run hangfire on a seperate sql server so are speculating that maybe the connection to that server went down briefly. Searching for examples of this happening currently.
What I’ve learnt from the hangfire job storage error:
ERROR: “JobStorage.Current property value has not been initialized. You must set it before using Hangfire Client or Server API.”
It is caused by a server reset. In this case the server reset about 15 seconds before.
EVENT LOG: “EVENTLOG_INFORMATION_TYPE #467421 Microsoft-Windows-WAS A worker process with process id of ‘4628’ serving application pool ‘MyPool’ has requested a recycle because the worker process reached its allowed processing time limit.MyPool/System”
It does not appear like the startup.cs module was run, in which case the hangfire server could run through its configuration process.
I have moved the initial configuration to the global.asax start up.
I have added logging to the startup module to try and see if the startup.cs does not run in some cases.
I have added a second configuration call to Application_Error to re-add the configuration if the exception is thrown again
This could possibly be due to IIS not detecting the OWIN startup?