[ 
https://issues.apache.org/jira/browse/AXIOM-524?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Michael Suhr updated AXIOM-524:
-------------------------------
    Description: 
I don't know if it's an issue for Axiom, Axis or the underlying Http Client 
(Httpclient 5 in my case).

I have a wsdl Service and call them often. Sometimes an error is shown:

{noformat}
org.apache.axiom.om.OMException: java.io.IOException: Attempted read on closed 
stream.
        at 
org.apache.axiom.om.impl.common.factory.meta.DetachableInputStream.detach(DetachableInputStream.java:75)
        at 
org.apache.axiom.om.impl.common.builder.OMXMLParserWrapperImpl.detach(OMXMLParserWrapperImpl.java:92)
        at 
org.apache.axis2.kernel.TransportUtils.detachInputStream(TransportUtils.java:578)
...
Caused by: java.io.IOException: Attempted read on closed stream.
        at 
org.apache.hc.core5.http.io.EofSensorInputStream.isReadAllowed(EofSensorInputStream.java:107)
        at 
org.apache.hc.core5.http.io.EofSensorInputStream.read(EofSensorInputStream.java:133)
        at 
org.apache.axiom.blob.MemoryBlobOutputStreamImpl.readFrom(MemoryBlobOutputStreamImpl.java:83)
        at org.apache.axiom.blob.MemoryBlobImpl.readFrom(MemoryBlobImpl.java:67)
        at 
org.apache.axiom.om.impl.common.factory.meta.DetachableInputStream.detach(DetachableInputStream.java:73)
{noformat}

For some investigation I added some breakpoints in IntelliJ to force a sleep.
h5. Debugging hints
- Add breakpoint with Evaluate at:
{code:java|title=org.apache.axiom.om.impl.common.factory.meta.DetachableInputStream#detach}
// Some comments here
    @Override
    public void detach() throws OMException {
        MemoryBlob blob = Blobs.createMemoryBlob(); //<-- add log here to see 
when its called
        try {
            blob.readFrom(target); <-- add here breakpoint (no suspend) with 
Thread.sleep(2000) and log that it shoul read
        } catch (StreamCopyException ex) {
            throw new OMException(ex.getCause()); <-- Here Breapoint to stop on 
error
        }
        if (closeOnDetach) {
            try {
                target.close();
            } catch (IOException ex) {
                throw new OMException(ex);
            }
        }
        target = blob.readOnce();
    }
{code}
- add beakpoint with log {{"close " + Thread.currentThread().getName() + " - " 
+ this.toString()}}:
{code:java|title=org.apache.hc.core5.http.io.EofSensorInputStream#close}
// Some comments here
    public void close() throws IOException {
        // tolerate multiple calls to close()
        selfClosed = true; // <-- add here the Log
        checkClose();
    }
{code}

If the service is now called twice I got the following log:

{noformat}
close http-nio-8280-exec-8 - 
org.apache.hc.core5.http.io.EofSensorInputStream@415a5c70
isReadAllowed: http-nio-8280-exec-8 - 
org.apache.hc.core5.http.io.EofSensorInputStream@757826d0: true
detach http-nio-8280-exec-8 - 
org.apache.hc.core5.http.io.EofSensorInputStream@757826d0
Breakpoint reached at 
org.apache.hc.core5.http.io.EofSensorInputStream.close(EofSensorInputStream.java:174)
close http-nio-8280-exec-6 - 
org.apache.hc.core5.http.io.EofSensorInputStream@757826d0
isReadAllowed: http-nio-8280-exec-6 - 
org.apache.hc.core5.http.io.EofSensorInputStream@48d7382c: true
detach http-nio-8280-exec-6 - 
org.apache.hc.core5.http.io.EofSensorInputStream@48d7382c
detach after sleep:     http-nio-8280-exec-8 - 
org.apache.hc.core5.http.io.EofSensorInputStream@757826d0
isReadAllowed: http-nio-8280-exec-8 - 
org.apache.hc.core5.http.io.EofSensorInputStream@757826d0: false
detach after sleep:     http-nio-8280-exec-6 - 
org.apache.hc.core5.http.io.EofSensorInputStream@48d7382c
isReadAllowed: http-nio-8280-exec-6 - 
org.apache.hc.core5.http.io.EofSensorInputStream@48d7382c: true
Breakpoint reached at 
org.apache.hc.core5.http.io.EofSensorInputStream.close(EofSensorInputStream.java:174)
close http-nio-8280-exec-6 - 
org.apache.hc.core5.http.io.EofSensorInputStream@48d7382c
Breakpoint reached at 
org.apache.axiom.om.impl.common.factory.meta.DetachableInputStream.detach(DetachableInputStream.java:75)
detach after sleep:     http-nio-8280-exec-8 - 
org.apache.hc.core5.http.io.EofSensorInputStream@757826d0
Breakpoint reached at 
org.apache.hc.core5.http.io.EofSensorInputStream.close(EofSensorInputStream.java:174)
close http-nio-8280-exec-8 - 
org.apache.hc.core5.http.io.EofSensorInputStream@757826d0
{noformat}
 You see that for {{EofSensorInputStream@757826d0}} the thread 
{{http-nio-8280-exec-8}} enter the detach method. but in meantime the thread 
{{http-nio-8280-exec-6 }} call close on it.

I try to create a running Test for it and if possible I will provide it to you 
as well

h5. Analysis
- If second call is executed metho 
{{org.apache.axis2.client.ServiceClient#createClient}} is called and 
{{AUTO_OPERATION_CLEANUP}} is true as default and then {{cleanupTransport}} is 
called
- 
{{org.apache.axis2.transport.http.impl.httpclient5.HTTPClient5TransportSender#cleanup}}
 cleanup the stream of Thread1 not checking if the message is currently still 
in use or not readed yet. Maybe add a marker that OperationCOntext is still in 
progress
- The generated {{Stub}} class calls in finally block 
{{_messageContext.getTransportOut().getSender().cleanup(_messageContext)}} but 
also via the {{AUTO_OPERATION_CLEANUP}}. Maybe it is enough to disable this for 
Stubs (like in 
{{org.apache.axis2.jaxws.description.impl.EndpointDescriptionImpl#getServiceClient}})

Maybe related to: AXIOM-517

  was:
I don't know if it's an issue for Axiom, Axis or the underlying Http Client 
(Httpclient 5 in my case).

I have a wsdl Service and call them often. Sometimes an error is shown:

{noformat}
org.apache.axiom.om.OMException: java.io.IOException: Attempted read on closed 
stream.
        at 
org.apache.axiom.om.impl.common.factory.meta.DetachableInputStream.detach(DetachableInputStream.java:75)
        at 
org.apache.axiom.om.impl.common.builder.OMXMLParserWrapperImpl.detach(OMXMLParserWrapperImpl.java:92)
        at 
org.apache.axis2.kernel.TransportUtils.detachInputStream(TransportUtils.java:578)
...
Caused by: java.io.IOException: Attempted read on closed stream.
        at 
org.apache.hc.core5.http.io.EofSensorInputStream.isReadAllowed(EofSensorInputStream.java:107)
        at 
org.apache.hc.core5.http.io.EofSensorInputStream.read(EofSensorInputStream.java:133)
        at 
org.apache.axiom.blob.MemoryBlobOutputStreamImpl.readFrom(MemoryBlobOutputStreamImpl.java:83)
        at org.apache.axiom.blob.MemoryBlobImpl.readFrom(MemoryBlobImpl.java:67)
        at 
org.apache.axiom.om.impl.common.factory.meta.DetachableInputStream.detach(DetachableInputStream.java:73)
{noformat}

For some investigation I added some breakpoints in IntelliJ to force a sleep.
h5. Debugging hints
- Add breakpoint with Evaluate at:
{code:java|title=org.apache.axiom.om.impl.common.factory.meta.DetachableInputStream#detach}
// Some comments here
    @Override
    public void detach() throws OMException {
        MemoryBlob blob = Blobs.createMemoryBlob(); //<-- add log here to see 
when its called
        try {
            blob.readFrom(target); <-- add here breakpoint (no suspend) with 
Thread.sleep(2000) and log that it shoul read
        } catch (StreamCopyException ex) {
            throw new OMException(ex.getCause()); <-- Here Breapoint to stop on 
error
        }
        if (closeOnDetach) {
            try {
                target.close();
            } catch (IOException ex) {
                throw new OMException(ex);
            }
        }
        target = blob.readOnce();
    }
{code}
- add beakpoint with log {{"close " + Thread.currentThread().getName() + " - " 
+ this.toString()}}:
{code:java|title=org.apache.hc.core5.http.io.EofSensorInputStream#close}
// Some comments here
    public void close() throws IOException {
        // tolerate multiple calls to close()
        selfClosed = true; // <-- add here the Log
        checkClose();
    }
{code}

If the service is now called twice I got the following log:

{noformat}
close http-nio-8280-exec-8 - 
org.apache.hc.core5.http.io.EofSensorInputStream@415a5c70
isReadAllowed: http-nio-8280-exec-8 - 
org.apache.hc.core5.http.io.EofSensorInputStream@757826d0: true
detach http-nio-8280-exec-8 - 
org.apache.hc.core5.http.io.EofSensorInputStream@757826d0
Breakpoint reached at 
org.apache.hc.core5.http.io.EofSensorInputStream.close(EofSensorInputStream.java:174)
close http-nio-8280-exec-6 - 
org.apache.hc.core5.http.io.EofSensorInputStream@757826d0
isReadAllowed: http-nio-8280-exec-6 - 
org.apache.hc.core5.http.io.EofSensorInputStream@48d7382c: true
detach http-nio-8280-exec-6 - 
org.apache.hc.core5.http.io.EofSensorInputStream@48d7382c
detach after sleep:     http-nio-8280-exec-8 - 
org.apache.hc.core5.http.io.EofSensorInputStream@757826d0
isReadAllowed: http-nio-8280-exec-8 - 
org.apache.hc.core5.http.io.EofSensorInputStream@757826d0: false
detach after sleep:     http-nio-8280-exec-6 - 
org.apache.hc.core5.http.io.EofSensorInputStream@48d7382c
isReadAllowed: http-nio-8280-exec-6 - 
org.apache.hc.core5.http.io.EofSensorInputStream@48d7382c: true
Breakpoint reached at 
org.apache.hc.core5.http.io.EofSensorInputStream.close(EofSensorInputStream.java:174)
close http-nio-8280-exec-6 - 
org.apache.hc.core5.http.io.EofSensorInputStream@48d7382c
Breakpoint reached at 
org.apache.axiom.om.impl.common.factory.meta.DetachableInputStream.detach(DetachableInputStream.java:75)
detach after sleep:     http-nio-8280-exec-8 - 
org.apache.hc.core5.http.io.EofSensorInputStream@757826d0
Breakpoint reached at 
org.apache.hc.core5.http.io.EofSensorInputStream.close(EofSensorInputStream.java:174)
close http-nio-8280-exec-8 - 
org.apache.hc.core5.http.io.EofSensorInputStream@757826d0
{noformat}
 You see that for {{EofSensorInputStream@757826d0}} the thread 
{{http-nio-8280-exec-8}} enter the detach method. but in meantime the thread 
{{http-nio-8280-exec-6 }} call close on it.

I try to create a running Test for it and if possible I will provide it to you 
as well

h5. Analysis
- If second call is executed metho 
{{org.apache.axis2.client.ServiceClient#createClient}} is called and 
{{AUTO_OPERATION_CLEANUP}} is true as default and then {{cleanupTransport}} is 
called
- 
{{org.apache.axis2.transport.http.impl.httpclient5.HTTPClient5TransportSender#cleanup}}
 cleanup the stream of Thread1 not checking if the message is currently still 
in use or not readed yet. Maybe add a marker that OperationCOntext is still in 
progress
- The generated {{Stub}} class calls in finally block 
{{_messageContext.getTransportOut().getSender().cleanup(_messageContext)}} but 
also via the {{AUTO_OPERATION_CLEANUP}}. Maybe it is enough to disable this for 
Stubs

Maybe related to: AXIOM-517


> Attempted read on closed stream for multithreaded environment
> -------------------------------------------------------------
>
>                 Key: AXIOM-524
>                 URL: https://issues.apache.org/jira/browse/AXIOM-524
>             Project: Axiom
>          Issue Type: Bug
>    Affects Versions: 1.4.0, 2.0.0
>            Reporter: Michael Suhr
>            Priority: Minor
>              Labels: AXIS2_1.8.2, AXIS2_2.0.0
>
> I don't know if it's an issue for Axiom, Axis or the underlying Http Client 
> (Httpclient 5 in my case).
> I have a wsdl Service and call them often. Sometimes an error is shown:
> {noformat}
> org.apache.axiom.om.OMException: java.io.IOException: Attempted read on 
> closed stream.
>       at 
> org.apache.axiom.om.impl.common.factory.meta.DetachableInputStream.detach(DetachableInputStream.java:75)
>       at 
> org.apache.axiom.om.impl.common.builder.OMXMLParserWrapperImpl.detach(OMXMLParserWrapperImpl.java:92)
>       at 
> org.apache.axis2.kernel.TransportUtils.detachInputStream(TransportUtils.java:578)
> ...
> Caused by: java.io.IOException: Attempted read on closed stream.
>       at 
> org.apache.hc.core5.http.io.EofSensorInputStream.isReadAllowed(EofSensorInputStream.java:107)
>       at 
> org.apache.hc.core5.http.io.EofSensorInputStream.read(EofSensorInputStream.java:133)
>       at 
> org.apache.axiom.blob.MemoryBlobOutputStreamImpl.readFrom(MemoryBlobOutputStreamImpl.java:83)
>       at org.apache.axiom.blob.MemoryBlobImpl.readFrom(MemoryBlobImpl.java:67)
>       at 
> org.apache.axiom.om.impl.common.factory.meta.DetachableInputStream.detach(DetachableInputStream.java:73)
> {noformat}
> For some investigation I added some breakpoints in IntelliJ to force a sleep.
> h5. Debugging hints
> - Add breakpoint with Evaluate at:
> {code:java|title=org.apache.axiom.om.impl.common.factory.meta.DetachableInputStream#detach}
> // Some comments here
>     @Override
>     public void detach() throws OMException {
>         MemoryBlob blob = Blobs.createMemoryBlob(); //<-- add log here to see 
> when its called
>         try {
>             blob.readFrom(target); <-- add here breakpoint (no suspend) with 
> Thread.sleep(2000) and log that it shoul read
>         } catch (StreamCopyException ex) {
>             throw new OMException(ex.getCause()); <-- Here Breapoint to stop 
> on error
>         }
>         if (closeOnDetach) {
>             try {
>                 target.close();
>             } catch (IOException ex) {
>                 throw new OMException(ex);
>             }
>         }
>         target = blob.readOnce();
>     }
> {code}
> - add beakpoint with log {{"close " + Thread.currentThread().getName() + " - 
> " + this.toString()}}:
> {code:java|title=org.apache.hc.core5.http.io.EofSensorInputStream#close}
> // Some comments here
>     public void close() throws IOException {
>         // tolerate multiple calls to close()
>         selfClosed = true; // <-- add here the Log
>         checkClose();
>     }
> {code}
> If the service is now called twice I got the following log:
> {noformat}
> close http-nio-8280-exec-8 - 
> org.apache.hc.core5.http.io.EofSensorInputStream@415a5c70
> isReadAllowed: http-nio-8280-exec-8 - 
> org.apache.hc.core5.http.io.EofSensorInputStream@757826d0: true
> detach http-nio-8280-exec-8 - 
> org.apache.hc.core5.http.io.EofSensorInputStream@757826d0
> Breakpoint reached at 
> org.apache.hc.core5.http.io.EofSensorInputStream.close(EofSensorInputStream.java:174)
> close http-nio-8280-exec-6 - 
> org.apache.hc.core5.http.io.EofSensorInputStream@757826d0
> isReadAllowed: http-nio-8280-exec-6 - 
> org.apache.hc.core5.http.io.EofSensorInputStream@48d7382c: true
> detach http-nio-8280-exec-6 - 
> org.apache.hc.core5.http.io.EofSensorInputStream@48d7382c
> detach after sleep:   http-nio-8280-exec-8 - 
> org.apache.hc.core5.http.io.EofSensorInputStream@757826d0
> isReadAllowed: http-nio-8280-exec-8 - 
> org.apache.hc.core5.http.io.EofSensorInputStream@757826d0: false
> detach after sleep:   http-nio-8280-exec-6 - 
> org.apache.hc.core5.http.io.EofSensorInputStream@48d7382c
> isReadAllowed: http-nio-8280-exec-6 - 
> org.apache.hc.core5.http.io.EofSensorInputStream@48d7382c: true
> Breakpoint reached at 
> org.apache.hc.core5.http.io.EofSensorInputStream.close(EofSensorInputStream.java:174)
> close http-nio-8280-exec-6 - 
> org.apache.hc.core5.http.io.EofSensorInputStream@48d7382c
> Breakpoint reached at 
> org.apache.axiom.om.impl.common.factory.meta.DetachableInputStream.detach(DetachableInputStream.java:75)
> detach after sleep:   http-nio-8280-exec-8 - 
> org.apache.hc.core5.http.io.EofSensorInputStream@757826d0
> Breakpoint reached at 
> org.apache.hc.core5.http.io.EofSensorInputStream.close(EofSensorInputStream.java:174)
> close http-nio-8280-exec-8 - 
> org.apache.hc.core5.http.io.EofSensorInputStream@757826d0
> {noformat}
>  You see that for {{EofSensorInputStream@757826d0}} the thread 
> {{http-nio-8280-exec-8}} enter the detach method. but in meantime the thread 
> {{http-nio-8280-exec-6 }} call close on it.
> I try to create a running Test for it and if possible I will provide it to 
> you as well
> h5. Analysis
> - If second call is executed metho 
> {{org.apache.axis2.client.ServiceClient#createClient}} is called and 
> {{AUTO_OPERATION_CLEANUP}} is true as default and then {{cleanupTransport}} 
> is called
> - 
> {{org.apache.axis2.transport.http.impl.httpclient5.HTTPClient5TransportSender#cleanup}}
>  cleanup the stream of Thread1 not checking if the message is currently still 
> in use or not readed yet. Maybe add a marker that OperationCOntext is still 
> in progress
> - The generated {{Stub}} class calls in finally block 
> {{_messageContext.getTransportOut().getSender().cleanup(_messageContext)}} 
> but also via the {{AUTO_OPERATION_CLEANUP}}. Maybe it is enough to disable 
> this for Stubs (like in 
> {{org.apache.axis2.jaxws.description.impl.EndpointDescriptionImpl#getServiceClient}})
> Maybe related to: AXIOM-517



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@ws.apache.org
For additional commands, e-mail: dev-h...@ws.apache.org

Reply via email to