hc-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Oleg Kalnichevski <ol...@apache.org>
Subject Re: BasicNIOConnPool Connection Lease
Date Mon, 16 Dec 2013 14:58:36 GMT
On Mon, 2013-12-16 at 15:21 +0100, Michael Nitschinger wrote:
> A Quick follow up on that one. I now did it like that and it seems to work:
> 
>     public void cleanup(final HttpHost host) {
>       enumAvailable(new PoolEntryCallback<HttpHost, NHttpClientConnection>() {
>         @Override
>         public void process(PoolEntry<HttpHost, NHttpClientConnection> entry) {
>           if (entry.getRoute().equals(host)) {
>             entry.close();
>           }
>         }
>       });
> 
>       enumLeased(new PoolEntryCallback<HttpHost, NHttpClientConnection>() {
>         @Override
>         public void process(PoolEntry<HttpHost, NHttpClientConnection> entry) {
>           if (entry.getRoute().equals(host)) {
>             entry.close();
>           }
>         }
>       });
>     }
> 
> but of course this can pretty much kill the selectors in flight.. that’s whats coming
up sometimes:
> 
> java.nio.channels.CancelledKeyException
> 	at sun.nio.ch.SelectionKeyImpl.ensureValid(SelectionKeyImpl.java:73)
> 	at sun.nio.ch.SelectionKeyImpl.interestOps(SelectionKeyImpl.java:77)
> 	at org.apache.http.impl.nio.reactor.IOSessionImpl.getEventMask(IOSessionImpl.java:138)
> 	at org.apache.http.impl.nio.DefaultNHttpClientConnection.consumeInput(DefaultNHttpClientConnection.java:266)
> 	at org.apache.http.impl.nio.DefaultHttpClientIODispatch.onInputReady(DefaultHttpClientIODispatch.java:165)
> 	at org.apache.http.impl.nio.DefaultHttpClientIODispatch.onInputReady(DefaultHttpClientIODispatch.java:51)
> 	at org.apache.http.impl.nio.reactor.AbstractIODispatch.inputReady(AbstractIODispatch.java:113)
> 	at org.apache.http.impl.nio.reactor.BaseIOReactor.readable(BaseIOReactor.java:159)
> 	at org.apache.http.impl.nio.reactor.AbstractIOReactor.processEvent(AbstractIOReactor.java:338)
> 	at org.apache.http.impl.nio.reactor.AbstractIOReactor.processEvents(AbstractIOReactor.java:316)
> 	at org.apache.http.impl.nio.reactor.AbstractIOReactor.execute(AbstractIOReactor.java:277)
> 	at org.apache.http.impl.nio.reactor.BaseIOReactor.execute(BaseIOReactor.java:105)
> 	at org.apache.http.impl.nio.reactor.AbstractMultiworkerIOReactor$Worker.run(AbstractMultiworkerIOReactor.java:584)
> 	at java.lang.Thread.run(Thread.java:722)
> 

Yes, that is the price for shutting down a connection mid-air (so to
speak). 

> Is there a better way to do this safely?
> 

You might just configure I/O reactor to silently ignore
CancelledKeyException. A more complex, but likely more proper way would
be to create a custom ConnectionReuseStrategy that is aware of unwanted
connection routes or unwanted connection instances.
ConnectionReuseStrategy can get hold of the underlying connection object
from the HttpContext instance passed in as a parameter.

Oleg



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


Mime
View raw message