title: "Connection reset" exception with Apache HttpClient 4.5 on Mac
body: <p>I need to get up to <strong>1000</strong> threads to send HTTP request simultaneously. Yet it seems on Mac I am hitting some limit, which causes Apache HTTPClient to return exception:</p>
  
  <pre><code>INFO: I/O exception (java.net.SocketException) caught when processing request to {}-&gt;http://my.url:80: Connection reset
  </code></pre>
  
  <p>The limit appears to be somewhere between 200 and 300 concurrent connections.</p>
  
  <p>I created a simple app and able to reproduce the issue even with that app:</p>
  
  <pre><code>import java.io.IOException;
  
  import org.apache.http.client.ClientProtocolException;
  import org.apache.http.client.methods.CloseableHttpResponse;
  import org.apache.http.client.methods.HttpGet;
  import org.apache.http.impl.client.CloseableHttpClient;
  import org.apache.http.impl.client.HttpClients;
  
  public class App implements Runnable
  {
      private static final int NUMBER_THREADS = 1000;
  
      public static void main( String[] args )
      {
          Thread[] threads = new Thread[NUMBER_THREADS];
          for(int i = 0; i &lt; NUMBER_THREADS; i++)
          {
              threads[i] = new Thread(new App()); 
          }
          for(int i = 0; i &lt; NUMBER_THREADS; i++)
          {
              threads[i].start(); 
          }
      }
  
      public void run() 
      {
          CloseableHttpClient httpclient = HttpClients.createDefault();
          HttpGet httpget = new HttpGet("http://my.url/test.html");
          CloseableHttpResponse response = null;
          try 
          {
              System.out.println( System.nanoTime() + " " + Thread.currentThread().getName() + " started" );
              response = httpclient.execute(httpget);
              System.out.println( System.nanoTime() + " " + Thread.currentThread().getName() + " finished" );
          } 
          catch (ClientProtocolException e) 
          {
              e.printStackTrace();
          } 
          catch (IOException e) 
          {
              e.printStackTrace();
          } 
          finally 
          {
              try 
              {
                  if(response != null)
                  {
                      response.close();
                  }
              } 
              catch (IOException e) 
              {
                  e.printStackTrace();
              }
          }
      }
  }
  </code></pre>
  
  <p>I updated some Mac settings, but that didn't help anything:</p>
  
  <pre><code>&gt; sysctl -a | grep files
  kern.maxfiles = 12288
  kern.maxfilesperproc = 10240
  kern.maxfiles: 12288
  kern.maxfilesperproc: 10240
  kern.num_files: 3202
  &gt; ulimit -n 10240
  &gt; ulimit -n
  10240
  &gt; sysctl -a | grep somax
  kern.ipc.somaxconn: 128
  &gt; sudo sysctl -w kern.ipc.somaxconn=2048
  Password:
  kern.ipc.somaxconn: 128 -&gt; 2048
  &gt; sysctl -a | grep somax
  kern.ipc.somaxconn: 2048
  </code></pre>
  
  <p>So I want to understand where this limit is coming from? OsX / Apache HttpClient itself? And is it possible to control it?</p>
  
  <p>Thanks in advance.</p>