Hello Hangfire Team,
I am encountering a recurring issue with Hangfire in my production environment, which manifests approximately once every six months. The Hangfire server is running as a Windows Service, and my application is based on the .NET Framework 4.8. The issue involves exceptions that lead to a failure in Hangfire’s processes.
Console Log Entries:
-
Warning Entry:
WARN: Server xxxxxxxx:8080:aab93526 encountered an exception while sending heartbeat
EXCEPTION: System.OutOfMemoryException: Exception of type 'System.OutOfMemoryException' was thrown. at Hangfire.SqlServer.SqlServerStorage.GetConnection() at Hangfire.Server.ServerHeartbeatProcess.Execute(BackgroundProcessContext context)
-
Error Entry:
ERROR: RunTask~Message:Error while generating Snapshot Changes: | FormattedException:Msg: 'Exception of type 'System.OutOfMemoryException' was thrown.', Type: 'OutOfMemoryException'
-
Fatal Entry:
FATAL: Dispatcher is stopped due to an exception, you need to restart the server manually. Please report it to Hangfire developers.
EXCEPTION: System.InvalidOperationException: Instance is read-only. at System.Collections.EmptyReadOnlyDictionaryInternal.Add(Object key, Object value) at Hangfire.Processing.BackgroundExecution.HandleException(Guid executionId, Exception exception, TimeSpan& delay) at Hangfire.Processing.BackgroundExecution.Run(Action
2 callback, Object state) at Hangfire.Processing.BackgroundDispatcher.DispatchLoop()`
These issues result in significant disruptions, necessitating a manual server restart. The infrequency of the problem makes diagnosis and prediction challenging.
I seek advice or guidance on the following:
- Potential causes for these exceptions, especially in the context of a .NET Framework 4.8 application running as a Windows Service.
- Best practices or configurations in a .NET Framework 4.8 environment that might help avoid these issues.
- Any known issues or patches in Hangfire related to these exceptions under similar environments.
Any insights or recommendations to address or mitigate these issues would be greatly appreciated.
Thank you for your assistance.