title: Httpclient throws Timeout waiting for connection from pool exception
body: <p>Now am working on an exception for our uploading image service, the scenario below:</p>
  
  <p>We have a web page, user from all over the world can upload their images to our server, the image normally keep about 3MB. Now we held a promotion, so the images number uploading to our server is extremely huge, which, however caused the server throws the exception as "org.apache.http.conn.ConnectionPoolTimeoutException: Timeout waiting for connection from pool".</p>
  
  <p>We use apache httpclient as the core uploading middleware, its version is 4.5.*, we correctly handled the response by using the method mentioned <a href="https://stackoverflow.com/questions/11875015/httpclient-exception-org-apache-http-conn-connectionpooltimeoutexception-timeo">in this article</a>.
  The code like below:</p>
  
  <pre><code> if (returnType != StorageHttpResponse.class &amp;&amp; response != null) {
          EntityUtils.consumeQuietly(response.getEntity());
          httpRequest.abort();
      }
  </code></pre>
  
  <p>Also, the max connection pool for the service is 128 and the max connection time out is 50000 ms. We upload the images by using stream mode, not directly upload the image file.</p>
  
  <p>So here, I correctly handled the response entity by consuming it in finally code block, but I still can't stop the service throw connection pool timeout exception. </p>
  
  <p>Any other stuffs that I need to add to my service? Do I really using redis to make a queue to user's uploading requests and post handling?</p>
  
  <p>Whole code here:</p>
  
  <pre><code> public &lt;T&gt; T excute(Request request, Class&lt;T&gt; returnType) {
      Preconditions.checkState(!isShutDown, "JSSHttpClient is destory!");
      HttpRequestBase httpRequest = new HttpRequestBuild(this.credential).build(request);
      HttpResponse response = null;
      try {
          response = this.client.execute(httpRequest);
          if (errorHandler.hasError(request, response)) {
              int statusCode = response.getStatusLine().getStatusCode();
              log.warn("Unexpected response," + request + " http code [" + statusCode + "]");
              errorHandler.handleError(response);
          }
          if (returnType != null &amp;&amp; returnType != StorageHttpResponse.class) {
              return JsonMessageConverter.read(returnType, response);
          }
          if (returnType == StorageHttpResponse.class) {
              return (T) new StorageHttpResponse(response);
          }
      } catch (IOException e) {
          Throwables.propagate(e);
      } finally {
          if (returnType != StorageHttpResponse.class &amp;&amp; response != null) {
              EntityUtils.consumeQuietly(response.getEntity());
              httpRequest.abort();
          }
      }
      return null;
  }
  </code></pre>