Details
Description
I am getting an intermittent NPE when I try to close the output stream for a response. The channel is non-blocking and my code is running outside of the handler after a continuation was created. I previously wrote the header for an HTTP 1.0 style streaming response (i.e. no content length, non-chunked) on the connection and now I am trying to close the connection at the end of the document.
The exception I'm getting is:
java.lang.NullPointerException
at org.mortbay.jetty.HttpFields$2.hasNext(HttpFields.java:267)
at org.mortbay.jetty.HttpGenerator.completeHeader(HttpGenerator.java:379)
at org.mortbay.jetty.HttpConnection.commitResponse(HttpConnection.java:529)
at org.mortbay.jetty.HttpConnection$Output.close(HttpConnection.java:837)
at com.electriccloud.accelerator.service.BuildNotifier.cleanup(BuildNotifier.java:77)
I have tried to trace the problem in the debugger, and it appears the NPE happens because destroy() has already been called on the connection so the attempt to commit a response is working on a partially destroyed object. As far as I can tell, destroy() is being called from the selector thread. My speculation is that the failure is caused by a race between the selector thread detecting a disconnect from the remote side and my thread deciding to close the channel.
I'm having a hard time narrowing down the problem to a small test case, but let me know if you want me to inject any logging because the problem is reproducible within 10-20 minutes.
2007-12-12 20:35:12.984::WARN: handle failed
java.lang.IllegalStateException
at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:361)
at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:396)
at com.approuter.module.http.protocol.CIBoundedThreadPool$PoolThread.run(CIBoundedThreadPool.java:404)
java.lang.NullPointerException
at org.mortbay.jetty.HttpFields$1.hasMoreElements(HttpFields.java:230)
I am facing soemhting similar intermittently under heavy load. Looks like httpFields got destroyed before sending the resposne and while reading from them it cause Null pointer eception. I ma not sure why this is happening. Is there any work aord for this.
i am using 6.1.5 release.