Skip to content

Possible Memory Leak in Async code  #1506

@WayneHiller

Description

@WayneHiller

I believe I have discovered a memory leak in Http.Async.cs

void SetTimeout(IAsyncResult asyncResult)
        {
            if (Timeout != 0)
                ThreadPool.RegisterWaitForSingleObject(
                    asyncResult.AsyncWaitHandle,
                    TimeoutCallback, _timeoutState, Timeout, true
                );

            static void TimeoutCallback(object state, bool timedOut)
            {
                if (!timedOut)
                    return;

                if (!(state is TimeOutState tos))
                    return;

                lock (tos) tos.TimedOut = true;

                tos.Request?.Abort();
            }
        }

The handle In the call to ThreadPool.RegisterWaitForSingleObject is not saved and handle.Unregister is never called.

https://docs.microsoft.com/en-us/dotnet/api/system.threading.threadpool.registerwaitforsingleobject?view=netcore-3.1

My ANTS Memory Profiler is showing the leak.

image

Specifications

  • Version: 106.10.1
  • Platform: Win x64

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions