hc-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Oleg Kalnichevski (JIRA)" <j...@apache.org>
Subject [jira] [Resolved] (HTTPASYNC-77) Client leaks file descriptors if .execute() not called
Date Sat, 31 May 2014 18:22:02 GMT

     [ https://issues.apache.org/jira/browse/HTTPASYNC-77?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]

Oleg Kalnichevski resolved HTTPASYNC-77.
----------------------------------------

       Resolution: Fixed
    Fix Version/s: 4.0.2

Fixed in HttpCore (trunk and 4.3.x)

http://svn.apache.org/r1598890
http://svn.apache.org/r1598891

Oleg

> Client leaks file descriptors if .execute() not called
> ------------------------------------------------------
>
>                 Key: HTTPASYNC-77
>                 URL: https://issues.apache.org/jira/browse/HTTPASYNC-77
>             Project: HttpComponents HttpAsyncClient
>          Issue Type: Bug
>    Affects Versions: 4.0.1
>         Environment: Ubuntu 12.04, possibly others
>            Reporter: Paul Draper
>              Labels: performance
>             Fix For: 4.0.2
>
>
> This leaks one anon_inode and two pipes:
> {code:java}
> CloseableHttpAsyncClient client = HttpAsyncClients.createDefault();
> client.start();
> client.close();
> {code}
> This does not:
> {code:java}
> CloseableHttpAsyncClient client = HttpAsyncClients.createDefault();
> client.start();
> client.execute(new HttpGet("https://issues.apache.org/jira/"), null);
> client.close();
> {code}
> Full sample code (for Linux):
> {code:java}
> import org.apache.http.client.methods.HttpGet;
> import org.apache.http.impl.nio.client.CloseableHttpAsyncClient;
> import org.apache.http.impl.nio.client.HttpAsyncClients;
> import java.io.BufferedReader;
> import java.io.IOException;
> import java.io.InputStreamReader;
> import java.lang.management.ManagementFactory;
> import java.util.concurrent.ExecutionException;
> public class Benchmark {
>     public static void main(String[] args) throws ExecutionException, InterruptedException,
IOException  {
>         printFileDescriptorCounts();
>         for(int i = 0; i < 20; i++) {
>             CloseableHttpAsyncClient client = HttpAsyncClients.createDefault();
>             client.start();
>             // uncomment the next line to fix the leak
>             // client.execute(new HttpGet("http://stackoverflow.com/questions/23966483"),
null);
>             client.close();
>             printFileDescriptorCounts();
>         }
>     }
>     // not portable -- Linux only
>     private static void printFileDescriptorCounts() throws IOException {
>         String processId = ManagementFactory.getRuntimeMXBean().getName().split("@")[0];
>         String cmd = String.format("lsof -p %s | grep 'anon_inode\\|pipe' | awk '{ print
$NF; }' | sort | uniq -c", processId);
>         Process process = Runtime.getRuntime().exec(new String[]{"/bin/sh", "-c", cmd});
>         BufferedReader br = new BufferedReader(new InputStreamReader(process.getInputStream()));
>         try {
>             for(String line; (line = br.readLine()) != null; ) {
>                 System.out.print(line.replace("\n", "\t"));
>             }
>             System.out.println();
>         } finally {
>             br.close();
>             process.destroy();
>         }
>     }
> }
> {code}



--
This message was sent by Atlassian JIRA
(v6.2#6252)

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@hc.apache.org
For additional commands, e-mail: dev-help@hc.apache.org


Mime
View raw message