Skip to content

Asp.Net Client can leak memory and trigger large number of exceptions #164

Open
@oldcookie

Description

@oldcookie

Describe the bug

Asp.Net client would keep adding the same middleware to the static _globalClient if Bugsnag.Client.Current is called outside of a request scope and call to BeginNotify() is called subsequently to add a middleware.

This results in a memory leak since _globalClient is static. When Notify() is called, this also results a very long running loop and a lot of handled exceptions due to the large number of middleware linked to the globalclient.

Steps to reproduce

  1. Invoke a async function with ConfigureAwait(false) or use Task.Run()
  2. Get a BugSnag client using Bugsnag.Client.Current when the HttpContext.current is no long in scope.
  3. Add a middleware.
  4. Repeat this across many requests
  5. Trigger Notify() on the global client

You would see a lot of exceptions in performance counters.

Environment

  • Bugsnag version: N/A
  • .NET framework version: 4.7.2

BeforeNotify() should probably check if it is using the _globalClient and not add a middleware or middleware should be stored using a HashSet instead to prevent duplicates.

Metadata

Metadata

Assignees

No one assigned

    Labels

    backlogWe hope to fix this feature/bug in the futurebugConfirmed bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions