.net core 2.1 OutOfMemory exception on linux/ubuntu x64

aspnetcore
dotnetcore
memory-storage
Tags: #<Tag:0x00007fa53b499548> #<Tag:0x00007fa53b499408> #<Tag:0x00007fa53b4992c8>

#1

Hello,
I use Hangfire for be background jobs on our .net project. Everything was good until i’ve migrated to .net core 2.1.
After that OutOfMemory exception is occurred when starting on ubuntu/linux. On Windows it works fine.
The same for 16.04 and 18.04 x64 versions
Here is stack trace:
Failed to process the job ‘7b533caf-bbf5-4e14-82ce-630940bdfb5f’: an exception occurred. Retry attempt 1 of 10 will be performed in 00:00:44.
System.OutOfMemoryException: Exception of type ‘System.OutOfMemoryException’ was thrown.
at System.RuntimeTypeHandle.GetTypeByName(String name, Boolean throwOnError, Boolean ignoreCase, Boolean reflectionOnly, StackCrawlMarkHandle stackMark, IntPtr pPrivHostBinder, Boolean loadTypeFromPartialName, ObjectHandleOnStack type, ObjectHandleOnStack keepalive)
at System.RuntimeTypeHandle.GetTypeByName(String name, Boolean throwOnError, Boolean ignoreCase, Boolean reflectionOnly, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean loadTypeFromPartialName)
at System.RuntimeType.GetType(String typeName, Boolean throwOnError, Boolean ignoreCase, Boolean reflectionOnly, StackCrawlMark& stackMark)
at System.Type.GetType(String typeName, Boolean throwOnError, Boolean ignoreCase)
at Hangfire.Storage.InvocationData.Deserialize()

Hangfire.Core version 1.6.20
Hangfire.AspNetCore version 1.6.20
Hangfire.MemoryStorage 1.5.2

Code for ConfigureServices:
public void ConfigureServices(IServiceCollection services)
{

			services.AddHangfire(config => config.UseMemoryStorage(new MemoryStorageOptions
			{
				
			}));
		}

Code for Configure method:

...
var options = new BackgroundJobServerOptions
			{
				SchedulePollingInterval = TimeSpan.FromSeconds(Constants.QueueJobInterval)
			};

			app.UseHangfireServer(options);

			app.Run(async (context) =>
			{
				await context.Response.WriteAsync("Worker started");
			});


			BackgroundJob.Schedule(() => serviceProvider.GetService<QueueJob<EmailQueueMessage>>().ProcessMessages(), TimeSpan.FromSeconds(Constants.QueueJobInterval));
...

Any help will be appreciated


#2

Issue has been solved. Problem was in generic types for running scheduled jobs
BackgroundJob.Schedule(() => serviceProvider.GetService<QueueJob<EmailQueueMessage>>().ProcessMessages(), TimeSpan.FromSeconds(Constants.QueueJobInterval));

Need to replace something like this to remove generic types for runner:
var jobRunner = serviceProvider.GetService<JobRunner>(); BackgroundJob.Schedule(() => jobRunner.ProcessEmailQueueJob(), TimeSpan.FromSeconds(Constants.QueueJobInterval));