System.AggregateException One or more errors occurred. (An operation on a socket could not be performed because the system lacked sufficient buffer space or because a queue was full

BhogleD 0 Reputation points
2025-04-07T23:37:13.23+00:00

ASP.NET Core version: 8.0.14

Language: C#

 

System.AggregateException One or more errors occurred. (An operation on a socket could not be performed because the system lacked sufficient

buffer space or because a queue was full. (api.orion.comcast.com:443)) at System.Threading.Tasks.Task.FinishContinuations()

at System.Threading.Tasks.Task.FinishSlow()

at System.Threading.Tasks.Task.TrySetException()

at System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1.SetException()

at System.Net.Http.RedirectHandler+<SendAsync>d__4.MoveNext()

at System.Threading.ExecutionContext.RunInternal() at System.Runtime.CompilerServices.AsyncTaskMethodBuilder1+AsyncStateMachineBox1.MoveNext()

at System.Runtime.CompilerServices.AsyncTaskMethodBuilder1+AsyncStateMachineBox1.MoveNext()

at System.Threading.Tasks.AwaitTaskContinuation.RunOrScheduleAction()

at System.Threading.Tasks.Task.RunContinuations()

at System.Threading.Tasks.Task.FinishContinuations()

at System.Threading.Tasks.Task.FinishSlow()

at System.Threading.Tasks.Task.TrySetException()

at System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1.SetException()

at System.Net.Http.DiagnosticsHandler+<SendAsyncCore>d__10.MoveNext()

at System.Threading.ExecutionContext.RunInternal()

at System.Runtime.CompilerServices.AsyncTaskMethodBuilder1+AsyncStateMachineBox1.MoveNext()

at System.Runtime.CompilerServices.AsyncTaskMethodBuilder1+AsyncStateMachineBox1.MoveNext()

at System.Threading.Tasks.AwaitTaskContinuation.RunOrScheduleAction()

at System.Threading.Tasks.Task.RunContinuations() at System.Threading.Tasks.Task.FinishContinuations()

at System.Threading.Tasks.Task.FinishSlow() at System.Threading.Tasks.Task.TrySetException()

at System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1.SetException() at System.Net.Http.HttpConnectionPool+<SendWithVersionDetectionAndRetryAsync>d__89.MoveNext()

at System.Threading.ExecutionContext.RunInternal() at System.Runtime.CompilerServices.AsyncTaskMethodBuilder1+AsyncStateMachineBox1.MoveNext()

at System.Runtime.CompilerServices.AsyncTaskMethodBuilder1+AsyncStateMachineBox1.MoveNext() at System.Threading.Tasks.AwaitTaskContinuation.RunOrScheduleAction()

at System.Threading.Tasks.Task.RunContinuations() at System.Threading.Tasks.Task.FinishContinuations() at System.Threading.Tasks.Task.FinishSlow()

at System.Threading.Tasks.Task.TrySetException() at System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1.SetException()

at System.Threading.Tasks.TaskCompletionSourceWithCancellation`1+<WaitWithCancellationAsync>d__1.MoveNext() at System.Threading.ExecutionContext.RunFromThreadPoolDispatchLoop()

at System.Runtime.CompilerServices.AsyncTaskMethodBuilder1+AsyncStateMachineBox1.MoveNext() at System.Runtime.CompilerServices.AsyncTaskMethodBuilder1+AsyncStateMachineBox1.ExecuteFromThreadPool()

at System.Threading.ThreadPoolWorkQueue.Dispatch() at System.Threading.PortableThreadPool+WorkerThread.WorkerDoWork() at System.Threading.PortableThreadPool+WorkerThread.WorkerThreadStart()

Caused by: System.Net.Http.HttpRequestException: An operation on a socket could not be performed because the system lacked sufficient buffer space or because a queue was full. (api.orion.comcast.com:443) --->

System.Net.Sockets.SocketException (10055): An operation on a socket could not be performed because the system lacked sufficient buffer space or because a queue was full.

at System.Net.Sockets.Socket.AwaitableSocketAsyncEventArgs.ThrowException(SocketError error, CancellationToken cancellationToken)

at System.Net.Sockets.Socket.<ConnectAsync>g__WaitForConnectWithCancellation|285_0(AwaitableSocketAsyncEventArgs saea, ValueTask connectTask, CancellationToken cancellationToken)

at System.Net.Http.HttpConnectionPool.ConnectToTcpHostAsync(String host, Int32 port, HttpRequestMessage initialRequest, Boolean async, CancellationToken cancellationToken)

--- End of inner exception stack trace --- at System.Net.Http.HttpConnectionPool.ConnectToTcpHostAsync(String host, Int32 port, HttpRequestMessage initialRequest, Boolean async, CancellationToken cancellationToken)

at System.Net.Http.HttpConnectionPool.ConnectAsync(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken)

at System.Net.Http.HttpConnectionPool.CreateHttp11ConnectionAsync(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken)

at System.Net.Http.HttpConnectionPool.AddHttp11ConnectionAsync(QueueItem queueItem)

at System.Threading.Tasks.TaskCompletionSourceWithCancellation`1.WaitWithCancellationAsync(CancellationToken cancellationToken)

at System.Net.Http.HttpConnectionPool.SendWithVersionDetectionAndRetryAsync(HttpRequestMessage request, Boolean async, Boolean doRequestAuth, CancellationToken cancellationToken)

at System.Net.Http.DiagnosticsHandler.SendAsyncCore(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken) at System.Net.Http.RedirectHandler.SendAsync(HttpRequestMessage re

Developer technologies ASP.NET ASP.NET Core
{count} votes

3 answers

Sort by: Most helpful
  1. Bruce (SqlWork.com) 77,686 Reputation points Volunteer Moderator
    2025-04-08T15:48:01.44+00:00

    the error means your code was sending packets faster than they could be delivered and overran the network output buffers. as windows does not support checking the status of the buffers, this error is the supported way of detecting the overrun.

    it appears you are getting the error at connection, meaning the requested server is not accepting packets (probably overloaded). your only recovery action is a random delay and try again. you may need to throttle your connection to the server. see polly for rate limiting:

    https://www.pollydocs.org

    0 comments No comments

  2. Ripin 11 Reputation points
    2025-06-20T19:09:14.3133333+00:00

    As the details provided is limited it's tough to understand the issue.

    The error typically indicates a problem with resource exhaustion on the client-side, specifically with managing socket connections. This can happen when an application creates too many connections without properly closing them, leading to a lack of available resources.

    Suggestion: Try to create a singleton HttpClient.

    0 comments No comments

  3. Jack Dang (WICLOUD CORPORATION) 225 Reputation points Microsoft External Staff
    2025-06-23T09:39:08.5166667+00:00

    Hi BhogleD,

    You're encountering this error:

    System.AggregateException: One or more errors occurred. (An operation on a socket could not be performed because the system lacked sufficient buffer space or because a queue was full...)

    This typically happens in .NET applications that make a large number of HTTP requests, especially when HttpClient is misused.

     

    This error is usually caused by:

    • Too many open sockets: Each new HttpClient instance opens a new socket. If not reused or disposed properly, sockets pile up.
    • Socket exhaustion: The system runs out of available ports or memory buffers.
    • Improper resource management: Not using HttpClient efficiently or not disposing of it correctly.

     

    Here are the key solutions, simplified:

    1. Use HttpClient Properly
    • Don’t create a new HttpClient for every request.
    • Instead, use a singleton HttpClient or use IHttpClientFactory (recommended in ASP.NET Core).
    • This avoids socket exhaustion and improves performance.
    1. Monitor and Limit Concurrent Requests
    • If you're sending thousands of requests in parallel, consider throttling them.
    • Use tools like SemaphoreSlim to limit concurrency.
    1. Check System Resources
    • Monitor your system’s socket usage using tools like: netstat (Windows) , TCPView (from Sysinternals)
    • If needed, adjust system settings like ephemeral port range or TCP wait time. (Advanced users only)

    Hope my answer would help. Kindly provide us the relevant code so we could analyze it further. If you have extra questions, please click "Comment".

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.