Yongxing Wang wrote:
Hi,

We are using HTTP-NIO 4.0 to communicate with our internal http servers, on a very high volume bases (80Mbits/second on both upload and download). We use AsyncNHttpClientHandler and DefaultClientIOEventDispatch.

We are seeing some strange behaviors randomly. After putting some debug 
messages and we finally identify the following exception that causes us great 
sorrow:


java.lang.NullPointerException
at org.apache.http.nio.protocol.AsyncNHttpClientHandler.outputReady(AsyncNHttpClientHandler.java:266) at org.apache.http.impl.nio.DefaultNHttpClientConnection.produceOutput(DefaultNHttpClientConnection.java:213) at org.apache.http.impl.nio.DefaultClientIOEventDispatch.outputReady(DefaultClientIOEventDispatch.java:152) at org.apache.http.impl.nio.reactor.BaseIOReactor.writable(BaseIOReactor.java:177) at org.apache.http.impl.nio.reactor.AbstractIOReactor.processEvent(AbstractIOReactor.java:317) at org.apache.http.impl.nio.reactor.AbstractIOReactor.processEvents(AbstractIOReactor.java:294) at org.apache.http.impl.nio.reactor.AbstractIOReactor.execute(AbstractIOReactor.java:256) at org.apache.http.impl.nio.reactor.BaseIOReactor.execute(BaseIOReactor.java:96) at org.apache.http.impl.nio.reactor.AbstractMultiworkerIOReactor$Worker.run(AbstractMultiworkerIOReactor.java:556) at java.lang.Thread.run(Thread.java:619)

It happens randomly and happens with HTTP GET. Look at the line 266, it is:

int statusCode = response.getStatusLine().getStatusCode();

It seems that the "response" is returned prematurely.

I think the line that causes NPE is this one

http://hc.apache.org/httpcomponents-core/httpcore-nio/xref/org/apache/http/nio/protocol/AsyncNHttpClientHandler.html#266

What seems obviously wrong is that AsyncNHttpClientHandler#outputReady event gets triggered for a GET request. This is not supposed to happen at all as GET requests are not supposed to enclose a content body.

However, this _could_ be caused by a race condition if multiple threads were to access the same connection object simultaneously. HTTP connections objects are NOT thread-safe. It is _strongly_ recommended HTTP connections should NEVER be accessed ouside the AsyncNHttpClientHandler events.

Thread safety issue would be my primary guess here, especially given the fact the problems seems to happen randomly.


This NullPointerException will propagate all the way up to IOReactorExceptionHandler "handle(RuntimeException ex);", where you only have two options, ignore it or shutdown the whole IoReactor (neither of the two is good for us). I guess the root problem is that we should never see that NPE.

Is there any more information I can provide to help address this problem?


Yes, a test case reproducing the problem or some contextual information would be great.

One can add some rudimentary wire / context logging to HttpCore NIO using these classes:

http://svn.apache.org/repos/asf/httpcomponents/httpcore/trunk/contrib/src/main/java/org/apache/http/contrib/logging/

Hope this helps somewhat.

Oleg

thanks,
Yong


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to