question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Memory leak with the Microsoft Dependency Injection job factory

See original GitHub issue

Describe the bug

Quartz.NET appears to leak memory when running jobs with the Microsoft.Extensions.DependencyInjection job factory.

Version used

3.6.3

To Reproduce

https://github.com/danports/MemoryLeakTest

Expected behavior

Memory usage should remain relatively stable; instead, it increases without bound: image

Additional context I’m wondering if Quartz.NET is not properly disposing the service scope created for running jobs - when I review the heap in the debugger, it appears that none of the ApplicationDbContext instances are freed even though some of the TestJob instances are.

Issue Analytics

  • State:closed
  • Created 2 months ago
  • Comments:6

github_iconTop GitHub Comments

2reactions
danportscommented, Jul 28, 2023

Alright, upon further investigation, this is an issue with neither Quartz.NET nor the Sentry .NET SDK - it’s a known problem with the runtime (https://github.com/mono/mono/issues/19665), which apparently gets triggered through the (indirect) interactions between Quartz.NET and Sentry when a Quartz job fails and Sentry logs the exceptions. I guess I got lucky with the previous scheduling engine I was using because it didn’t trigger this issue, which made me suspect Quartz.NET when it was actually the runtime at fault. Sorry for the false alarm!

0reactions
danportscommented, Jul 28, 2023

When I remove Quartz.NET from the repro project (by cutting out the scheduler and executing the TestJob directly), I am unable to reproduce the problem, so I can’t yet rule out an issue with Quartz.NET. Continuing to dig deeper.

Read more comments on GitHub >

github_iconTop Results From Across the Web

EF Core Context is causing memory leak
My software using EF Core in combination with a SQLite database within an ASP.NET Core Web API using dependency injection, has a memory...
Read more >
Memory Leaks using Dependency Injection with .NET Core
I inherited a .NET Core application that had a memory leak. I found the source to be the way the application used the...
Read more >
8 Ways You can Cause Memory Leaks in .NET
WPF Bindings can actually cause memory leaks. The rule of thumb is to always bind to a DependencyObject or to a INotifyPropertyChanged object....
Read more >
Debug a memory leak in .NET Core
A memory leak may happen when your app references objects that it no longer needs to perform the desired task.
Read more >
Memory Leak · Issue #125 · quartznet ...
In our case, we are using Custom JobFactory and Simple Injector for creating the instances of jobs and to inject other dependencies.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found