Uploaded image for project: 'Solr'
  1. Solr
  2. SOLR-13545

ContentStreamUpdateRequest no longer closes stream

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 7.4, 7.5, 7.6, 7.7, 7.7.1, 7.7.2, 8.0, 8.1, 8.1.1
    • 8.2
    • SolrJ
    • None
    • Windows - file locking may not cause a visible failure on Linux?

    Description

      Since the change made in SOLR-12142 ContentStreamUpdateRequest no longer closes the stream that it opens. Therefore if streaming a file, it cannot be deleted until the process exits.

       

      @Override
        public RequestWriter.ContentWriter getContentWriter(String expectedType) {
          if (contentStreams == null || contentStreams.isEmpty() || contentStreams.size() > 1) return null;
          ContentStream stream = contentStreams.get(0);
          return new RequestWriter.ContentWriter() {
            @Override
            public void write(OutputStream os) throws IOException {
              IOUtils.copy(stream.getStream(), os);
            }
      
            @Override
            public String getContentType() {
              return stream.getContentType();
            }
          };
        }
      

      IOUtils.copy will not close the stream. Adding a close to the write(), is enough to "fix" it for the test case I've attached, e.g.

       

            @Override
            public void write(OutputStream os) throws IOException {
                final InputStream innerStream = stream.getStream();
                try {
                  IOUtils.copy(innerStream, os);
                } finally {
                  IOUtils.closeQuietly(innerStream);
                }
            }
      
      

       

      I don't know whether any other streaming classes have similar issues

       

       

      Attachments

        1. ContentStreamUpdateRequestBug.java
          1 kB
          cjcowie
        2. SOLR-13545.patch
          4 kB
          Mikhail Khludnev
        3. SOLR-13545.patch
          4 kB
          Mikhail Khludnev
        4. SOLR-13545.patch
          4 kB
          Mikhail Khludnev

        Issue Links

          Activity

            People

              Unassigned Unassigned
              colvinco Colvin Cowie
              Votes:
              0 Vote for this issue
              Watchers:
              6 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Time Tracking

                  Estimated:
                  Original Estimate - Not Specified
                  Not Specified
                  Remaining:
                  Remaining Estimate - 0h
                  0h
                  Logged:
                  Time Spent - 1h 50m
                  1h 50m