Skip to content

Out of memory exception with high exceptions rate in multi threaded environment #296

@sanjaysingh

Description

@sanjaysingh

Describe the bug
Rollbar seems to be causing out of memory issues when a multi threaded application causes burst of exceptions in short span of time.

To Reproduce
We were able to write a .Net console app with just the enough code to show the behavior that we think is affecting us. The memory usage keeps growing up when application is continuously pumping exceptions from multiple threads. In this example we only used 5 threads but in the real application where we use Rollbar we have 100s of threads. Understand that following example is just a representation of the issue to simplify reproducing of the problem; it does not depict how the Rollbar is being used in the application. In actual application, Rollbar is used with Log4Net using an appender.

The error can also be reproduced if you use incorrect access code that you might want to do so that Rollbar is not flooded with all these dummy exceptions.

using System;
using System.Threading.Tasks;
using System.Configuration;
using Rollbar;
using System.Diagnostics;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            var config = new RollbarConfig(ConfigurationManager.AppSettings["Rollbar.AccessToken"])
            {
                Environment = "Development"
            };
            var rollBar = RollbarFactory.CreateNew().Configure(config);
            int threadsCount = 5;
            Console.WriteLine($"Enter to start sending stream of messages on {threadsCount} threads.");
            Console.ReadLine();
            for (int i = 0; i < threadsCount; i++)
            {
                Task.Run(() =>
                {
                    while (true)
                    {
                        rollBar.Error(new System.Exception("A dummy exception occurred".PadRight(1024, 'Z')));
                    }
                });

            }
            Task.Run(() => 
            {
                while (true)
                {
                    Console.WriteLine($"Memory used: {Process.GetCurrentProcess().PrivateMemorySize64 / (1024 * 1024) }MB");
                    Task.Delay(1000).Wait();
                }
            });
            Console.WriteLine("Done creating tasks. Enter to exit");
            Console.ReadLine();
        }
    }
}

Expected behavior
Flooding of exceptions should not cause extra memory pressure on the application just because we are trying to send those errors to Rollbar. Seems like the errors get cached in memory and it cannot keep with the rate of exceptions being generated. If the application is already under pressure because of some issues in downstream dependencies, the logger (Rollar) should not aggravate that situation. There might be a possibility of implementing some rate limiting / buffer limiting on the client side if it is not already there.

Screenshots
Memory graph taken from Visual Studio 2017 in-built memory profiler
image

Console log showing how memory usage is increasing
image

Rollbar Client - Rollbar.NET Hosting Environment

  • Rollbar.NET Host type: Azure Worker Role, Console Application

  • OS and its version: Windows Server 2012, Windows 10

  • .NET flavor and its version: .Net Framework 4.6.2

  • Rollbar.NET Version: 2.1.0

  • Applicable custom third party logging library/framework integration (if any): Log4Net

Metadata

Metadata

Assignees

Labels

bugDenotes a runtime problem within the SDKquestion

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions