I have a background service to monitor the Hangfire Server e.g. Check if some jobs are stuck in processing or check if the number enqueued jobs are greater than a set threshold.
Background Service runs every 3 mins and initialized the monitoringAPI instance and checks the required conditions. If those are true it just sends an alert email.
Issue is after sometime e.g. 5-10 mins, the number of database connections increases to 50-60 at max. After that I get ‘Too Many Connections’ exception while connecting to DB. I can increase the max number of connections to my DB but what is the issue with MonitoringAPI? What it is creating connections and not closing it afterwards?
I have tried to dispose the monitoring API variable but it’s not disposable. I have tried to add some checks to not initialize monitoring API if it already exists but still it keeps on creating the DB connections.
Any solutions or tips?
Thanks in advance