Uploaded image for project: 'Java Driver'
  1. Java Driver
  2. JAVA-2294

GridFSDownloadStream - exception when destination buffer size != file chunk size

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • 3.4.0
    • Affects Version/s: 3.3.0
    • Component/s: API
    • None

      When using GridFSDownloadStream to download a file with multiple chunks, if you use a destination buffer whose size is not exactly equal to the file's chunk size then you will get the following exception:

      com.mongodb.MongoGridFSException: Could not find file chunk for files_id: BsonObjectId{value=57c87e6afc76010ce8f43887} at chunk index 2.
      
      	at com.mongodb.async.client.gridfs.GridFSDownloadStreamImpl.chunkNotFound(GridFSDownloadStreamImpl.java:235)
      	at com.mongodb.async.client.gridfs.GridFSDownloadStreamImpl.access$600(GridFSDownloadStreamImpl.java:38)
      	at com.mongodb.async.client.gridfs.GridFSDownloadStreamImpl$5.onResult(GridFSDownloadStreamImpl.java:168)
      	at com.mongodb.async.client.gridfs.GridFSDownloadStreamImpl$5.onResult(GridFSDownloadStreamImpl.java:162)
      	at com.mongodb.operation.AsyncQueryBatchCursor.next(AsyncQueryBatchCursor.java:109)
      	at com.mongodb.async.client.gridfs.GridFSDownloadStreamImpl.checkAndFetchResults(GridFSDownloadStreamImpl.java:162)
      	at com.mongodb.async.client.gridfs.GridFSDownloadStreamImpl.read(GridFSDownloadStreamImpl.java:132)
      

      I have created a GIST for a JUnit test which demonstrates the issue – https://gist.github.com/sfitts/6ac8fc6efa19ef86600ae5354682c5ca

      The issue seems to be that the code decides to do a read-ahead into a chunk that doesn't exist (it is one off the edge) and so doesn't get to use the data already sitting in "buffer" to fulfill the read.

            Assignee:
            ross@mongodb.com Ross Lawley
            Reporter:
            smfitts@gmail.com Sean Fitts
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: