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

Larry McCay edited comment on KNOX-807 at 2/3/17 11:01 PM:
-----------------------------------------------------------

Yes, I can't quite get my head around this either.
[~treydone] - can you articulate the usage pattern here?
Is it different for say groovy scripting than for direct use of the classes on 
the server side?



was (Author: lmccay):
Yes, I can quite get my head around this either.
[~treydone] - can you articulate the usage pattern here?
Is it different for say groovy scripting than for direct use of the classes on 
the server side?


> 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.15#6346)

Reply via email to