Uploaded image for project: 'JBoss Enterprise Application Platform'
  1. JBoss Enterprise Application Platform
  2. JBEAP-11260

[GSS](7.1.0) Stream prematurely closed by finalizer

    XMLWordPrintable

Details

    • Bug
    • Status: Verified (View Workflow)
    • Major
    • Resolution: Done
    • None
    • 7.1.0.DR19
    • REST
    • None

    Description

      There's a problem when invoking jaxrs service returning "big enough" Streams (depends on platform, it is generally over 1Mo). There's an "InputStream closed" Exception that sounds like premature closing by java finalizer. Details :

      Caused by: java.lang.RuntimeException: java.io.IOException: Stream closed
                      at org.jboss.resteasy.client.jaxrs.engines.ApacheHttpClient4Engine.loadHttpMethod(ApacheHttpClient4Engine.java:381)
                      at org.jboss.resteasy.client.jaxrs.engines.ApacheHttpClient4Engine.invoke(ApacheHttpClient4Engine.java:232)
                      ... 21 more
      Caused by: java.io.IOException: Stream closed
                      at java.io.BufferedInputStream.getBufIfOpen(Unknown Source)
                      at java.io.BufferedInputStream.read(Unknown Source)
                      at org.jboss.resteasy.client.core.SelfExpandingBufferredInputStream.read(SelfExpandingBufferredInputStream.java:57)
                      at java.io.FilterInputStream.read(Unknown Source)
                      at org.jboss.resteasy.client.core.SelfExpandingBufferredInputStream.read(SelfExpandingBufferredInputStream.java:67)
                      at org.jboss.resteasy.plugins.providers.ProviderHelper.writeTo(ProviderHelper.java:124)
                      at org.jboss.resteasy.plugins.providers.DataSourceProvider.writeTo(DataSourceProvider.java:197)
                      at org.jboss.resteasy.plugins.providers.DataSourceProvider.writeTo(DataSourceProvider.java:31)
                      at org.jboss.resteasy.plugins.providers.multipart.AbstractMultipartWriter.writePart(AbstractMultipartWriter.java:60)
                      at fr.gouv.diplomatie.client.rest.utils.MultipartFormDataWriter.writePart(MultipartFormDataWriter.java:33)
                      at org.jboss.resteasy.plugins.providers.multipart.AbstractMultipartFormDataWriter.writeParts(AbstractMultipartFormDataWriter.java:33)
                      at org.jboss.resteasy.plugins.providers.multipart.AbstractMultipartWriter.write(AbstractMultipartWriter.java:33)
                      at org.jboss.resteasy.plugins.providers.multipart.MultipartFormDataWriter.writeTo(MultipartFormDataWriter.java:34)
                      at org.jboss.resteasy.plugins.providers.multipart.MultipartFormDataWriter.writeTo(MultipartFormDataWriter.java:18)
      

      Our service interface is defined by :

      @javax.ws.rs.GET
      @javax.ws.rs.Path(value="/document/{documentId}/content")
      @javax.ws.rs.Produces(value={"application/octet-stream"})
      public abstract javax.ws.rs.core.Response readContent(@javax.ws.rs.PathParam(value="documentId") java.lang.String id);
      

      And a sample usecase is :

      IOUtils.copy(service.readContent(id).readEntity(InputStream.class), fileOut);
      

      I have seen old issues about finalizer in ClientResponse class... so i tryed this silly thing and it works !

      Response res = service.readContent(id);
      InputStream is = res.readEntity(InputStream.class);
      IOUtils.copy(is, fileOut);
      

      there's some JVM tricks behin...managing automatic stream closing appears to be hard to solve ! It could be better to leave responsibility of cleanup to caller (managed with "try-with-resource" java pattern or IOUtils lib)

      Attachments

        Issue Links

          Activity

            People

              rhn-support-asoldano Alessio Soldano
              rhn-support-wsiqueir William Siqueira
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: