title: HttpClient : "Resource temporarily unavailable" when sending requests asynchronously
body: <p>I've written a application to generate a load to a REST API endpoint. Sending the requests synchronously from my local machine I can amount to around 15 Rps. I had the idea to send the requests asynchronously and when it works, I get 2-3x more Rps than in the beginning.</p>
  
  <p>The issue I have is that sending requests asynchronously usually (roughly 80% of the time) throws me an exception inside the HttpClient <code>Resource temporarily unavailable</code> and with inner exception of </p>
  
  <pre><code>{System.Net.Sockets.SocketException (11): Resource temporarily unavailable at System.Net.Http.ConnectHelper.ConnectAsync(String host, Int32 port, CancellationToken cancellationToken)}
  </code></pre>
  
  <p>Now, for my API client I have a single static HttpClient and a method SendRequestsAsync</p>
  
  <pre><code>        public async Task&lt;RestResponse[]&gt; SendRequestsAsync(string apiUrl, int count)
          {
              var tasks = new Task&lt;RestResponse&gt;[count];
  
              for (int i = 0; i &lt; count; i++)
              {
                  tasks[i] = SendRequest(apiUrl);
              }
  
              await Task.WhenAll(tasks);
              return tasks.Select(x =&gt; x.Result).ToArray();
          }
  </code></pre>
  
  <p>My assumption is that I'm running out of sockets but I don't know where go from here. Is there a way to run as many requests as possible on a machine without encountering this exception or a request to wait for available sockets? </p>