hc-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Bill Speirs <bill.spe...@gmail.com>
Subject Re: Too Many Open Files Exception
Date Mon, 31 Oct 2011 21:49:34 GMT
Yea, I don't think that the IOReactor is the issue... I think something
else is taking all the sockets and there are none left for the IOReactor to
call accept.

Do I need to consume all of the data from the entity before calling close
on the InputStream? For error conditions I thought that I should call
abort().

Also, if there is a read timeout on a connection to a host and that
connection is never closed, what happens when I ask the connection manager
for a connection to that same host/route? Would it still hand-out that bad
connection?

Bill-
On Oct 31, 2011 5:31 PM, "Oleg Kalnichevski" <olegk@apache.org> wrote:

> 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
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message