cxf-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Aki Yoshida <>
Subject Oneway CXF service having problem with Gemini-Web/Tomcat-catalina
Date Fri, 17 Jun 2011 22:46:52 GMT
There seems to be some IO handling problem in oneway CXF services on
equinox with the latest gemini-web.
It think I have identified the cause of the problem and that we could
fix it in CXF. But I would like to get your comments.

The problem happens sporadically for oneway services when the
StaxInInterceptor tries to instantiate the XMLStreamReader from the
InputStream object. In this test scenario, a series of oneway calls
are sequentially sent to a CXF oneway service. And sporadically, some
calls result in the following exception, that is indicating the input
stream is already closed, even though the data should be available in
the stream.

Caused by: java.lang.RuntimeException: Couldn't parse stream.
	at org.apache.cxf.staxutils.StaxUtils.createXMLStreamReader(
	at org.apache.cxf.interceptor.StaxInInterceptor.handleMessage(
	... 27 common frames omitted
Caused by: com.ctc.wstx.exc.WstxIOException: Stream closed
	at com.ctc.wstx.stax.WstxInputFactory.doCreateSR(
	at com.ctc.wstx.stax.WstxInputFactory.createSR(
	at com.ctc.wstx.stax.WstxInputFactory.createSR(
	at com.ctc.wstx.stax.WstxInputFactory.createXMLStreamReader(
	at org.apache.cxf.staxutils.StaxUtils.createXMLStreamReader(
	... 28 common frames omitted
Caused by: Stream closed
	at ~[na:na]
	at ~[na:na]
	at ~[na:na]
	at com.ctc.wstx.stax.WstxInputFactory.doCreateSR(

I didn't see this problem with jetty before and started to see this
problem sporadically right after switching to gemini-web.

It seems that the error has something to do with the way in which its
previous call is handled and how the servlet container manages the
stream resources. To investigate this situation, I logged CXF's each
method call into the HttpServletRequest, HttpServetResponse,
ServletInputStream, and ServerOutputStream objects and noticed that
the input stream was always closed by a web container's cleanup thread
instead of the CXF's servlet thread. In contrast, the output stream
was always closed by the CXF servlet thread at
AbstractHTTPDestination's close(). In this method, there is an
interesting code fragment that explains this particular handling for
the oneway case:

        public void close(Message msg) throws IOException {
            if (msg.getExchange() == null) {
            Message m = msg.getExchange().getInMessage();
            if (m == null || msg.getExchange().isOneWay()) {
            InputStream is = m.getContent(InputStream.class);
            if (is != null) {
                try {

The intention of the above code was probably to asynchronously read
the input stream later than this point. But if the output stream is
closed and the servlet is returned, there is no guarantee that the
input stream remains available. So, I think we can close the input
stream there. Besides, OneWayProcessorInterceptor is supposed to be
pulling in the entire stream data.

            if (Boolean.FALSE.equals(o)) {
                //need to suck in all the data from the input stream as
                //the transport might discard any data on the stream when this
                //thread unwinds or when the empty response is sent back
                DelegatingInputStream in =
                if (in != null) {

So, I modified the AbstractHTTPDestination's close method to also
close the input stream upon closing the output stream. And it seems
that the problem is gone. But I am not 100% sure that this might not
be introducing another problem.

My hypothesis is that Gemini-web (tomcat-catalina) closes the input
stream with some non-deterministic behavior that sporadically causes
the input stream of the subsequent call to become closed. I think if
tomcat-cataline always closes the input stream right away after the
call comes back, it will probably also solve this problem.

Should I go ahead to put this change in 2.5 and 2.4.x? Or do you think
we should discuss this issue with the tomcat-cataline people?


Regards, aki

View raw message