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.