[ 
https://issues.apache.org/jira/browse/KNOX-807?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15802469#comment-15802469
 ] 

Sumit Gupta commented on KNOX-807:
----------------------------------

[~treydone], adding a close method along with shutdown seemed a bit confusing 
to me. The client code will need to know what to call when. Can shutdown not 
simply release all resources? The argument I can see is if the user wants to 
cancel requests but keep using the session but that seems weird to me too. What 
are your thoughts on this?

Any input on this [~lmccay]?

> Missing resource deallocation
> -----------------------------
>
>                 Key: KNOX-807
>                 URL: https://issues.apache.org/jira/browse/KNOX-807
>             Project: Apache Knox
>          Issue Type: Bug
>          Components: ClientDSL
>            Reporter: Vincent Devillers
>            Assignee: Vincent Devillers
>              Labels: KIP-4
>             Fix For: 0.12.0
>
>         Attachments: KNOX-807.patch
>
>
> h2. Release connection to pool after HTTP call
> The close() method in BasicResponse does only 
> EntityUtils.consumeQuietly(response.getEntity()):
> {code}
>     public void close() {
>         this.consume();
>     }
>     public void consume() {
>         if(!this.consumed) {
>             EntityUtils.consumeQuietly(this.response.getEntity());
>             this.consumed = true;
>         }
>     }
> {code}
> The underlying HTTP connection is still held. In order to ensure correct 
> deallocation of OS resources we need to call CloseableHttpResponse#close() 
> like this:
> {code}
> public void close() {
>     try {
>         this.consume();
>     } finally {
>         if (response instanceof CloseableHttpResponse) {
>             try {
>                 ((CloseableHttpResponse) response).close();
>             } catch (IOException e) {
>                 throw Throwables.propagate(e);
>             }
>         }
>     }
> }
> {code}
> h2. Shutdown connection pool
> Also when the Hadoop session is no more used, the only method present by to 
> be call is shutdown(), but it close only the ExecutorService. When a 
> CloseableHttpClient instance is no longer needed, we have to shut down the 
> connection manager to ensure immediate deallocation of all OS resources.
> {code}
> public void close() {
>     try {
>       executor.shutdownNow();
>     } catch(Exception e) {
>       // log something here
>     }
>     try {
>       client.close();
>       // client.close() should call getConnectionManager().shutdown();
>     } catch(Exception e) {
>       // log something here
>     }
> }
> {code}
> [Source|https://blog.layer4.fr/2016/12/06/knox-production-pitfalls-and-common-mistakes/]



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to