After upgrading to Http Core 4.3, one of the integration tests intermittently fail with the following error:

2013-08-10 00:54:21,501 [-] [PassThroughMessageProcessor-1] ERROR PassThroughNHttpGetProcessor Error generating ?wsdl output for service : StockQuoteProxy
java.nio.BufferOverflowException
at java.nio.HeapByteBuffer.put(HeapByteBuffer.java:165)
at org.apache.http.nio.util.SimpleOutputBuffer.write(SimpleOutputBuffer.java:76)
at org.apache.http.nio.entity.ContentOutputStream.write(ContentOutputStream.java:72)
at org.apache.synapse.transport.passthru.api.PassThroughNHttpGetProcessor.sendResponseAndFinish(PassThroughNHttpGetProcessor.java:135)
at org.apache.synapse.transport.passthru.api.PassThroughNHttpGetProcessor.generateWsdl(PassThroughNHttpGetProcessor.java:181)
at org.apache.synapse.transport.passthru.api.PassThroughNHttpGetProcessor.process(PassThroughNHttpGetProcessor.java:110)
at org.apache.synapse.transport.passthru.ServerWorker.run(ServerWorker.java:182)
at org.apache.axis2.transport.base.threads.NativeWorkerPool$1.run(NativeWorkerPool.java:173)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:680)

This is a very specific scenario, where Synapse doesn't mediate the request, but responds to the HTTP request on its own (WSDL generation scenario). Any idea what could have cause this issue?

My guess is this is a race condition at the output buffer. SimpleOutputBuffer is not thread safe as per the HTTP Core API docs. But it is being accessed by server worker as well as the IO dispatcher in this particular scenario. I tried using the SharedOutputBuffer and it seems to fix the problem (need to test this further). Is this is a reasonable solution?

Thanks,
Hiranya
--
Hiranya Jayathilaka
Mayhem Lab/RACE Lab;
Dept. of Computer Science, UCSB;  http://cs.ucsb.edu
E-mail: hiranya@cs.ucsb.edu;  Mobile: +1 (805) 895-7443
Blog: http://techfeast-hiranya.blogspot.com