hc-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Oleg Kalnichevski <ol...@apache.org>
Subject Re: Too Many Open Files Exception
Date Mon, 31 Oct 2011 21:30:51 GMT
On Mon, 2011-10-31 at 15:26 -0400, Bill Speirs wrote:
> I'm having an issue with the NIO Reactor. I'm getting the following exception:
> 
> org.apache.http.nio.reactor.IOReactorException: Failure accepting connection
>         at org.apache.http.impl.nio.reactor.DefaultListeningIOReactor.processEvent(DefaultListeningIOReactor.java:169)
>         at org.apache.http.impl.nio.reactor.DefaultListeningIOReactor.processEvents(DefaultListeningIOReactor.java:149)
>         at org.apache.http.impl.nio.reactor.AbstractMultiworkerIOReactor.execute(AbstractMultiworkerIOReactor.java:370)
>         at my code where I call execute()
>         at java.lang.Thread.run(Thread.java:662)
> Caused by: java.io.IOException: Too many open files
>         at sun.nio.ch.ServerSocketChannelImpl.accept0(Native Method)
>         at sun.nio.ch.ServerSocketChannelImpl.accept(ServerSocketChannelImpl.java:152)
>         at org.apache.http.impl.nio.reactor.DefaultListeningIOReactor.processEvent(DefaultListeningIOReactor.java:165)
>         ... 4 more
> 

Bill

The NIO reactor is not necessarily the culprit. Connection descriptors
may be leaking elsewhere. 

> This code does some complex things including opening two connection
> (via HTTP Client) to other services. I believe that I'm correctly
> cleaning up those connections by getting the entity in the response to
> both, and calling close on the stream.
> 
> // first connection to another service
> InputStream is = response.getEntity().getContent();
> 
> // do stuff with is
> 
> is.close();
> 
> 
> // second connection to another service
> 
> HttpEntity entity = response.getEntity();
> 		    	
> if(entity != null) {
>      // close this to release the connection
>      entity.getContent().close();
> }
> 
> 
> That is all I need to do, correct? There isn't anything else to
> release the socket is there?
> 

You should probably be releasing connection resources from a try-finally
clause. This would ensure that resources get correctly released in case
of an abnormal situation: non 2xx response, runtime exception, etc 

HttpResponse response = httpclient.execute(httpget, context);
try {
// process response
} finally {
    EntityUtils.consume(response.getEntity());
}

Oleg



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


Mime
View raw message