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

Close operation on GridFsUploadStream is not idempotent

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Minor - P4 Minor - P4
    • 4.8.1
    • Affects Version/s: 4.8.0
    • Component/s: GridFS
    • Labels:
      None
    • Not Needed

      Summary

      Close operation is no longer idempotent due to change of the synchronization method. Calling more than once close operation on the stream tries to store file that many times (even if "closed" flag is set to true).

      This is due to return statement that previously was there for fast quit from the method, now just quits the Runnable.

      Please provide the version of the driver. If applicable, please provide the MongoDB server version and topology (standalone, replica set, or sharded cluster).

      mongodb-driver-sync:4.8.0

      the change that introduced that:

      https://github.com/mongodb/mongo-java-driver/commit/3ef3747d39fba98eb041f915e2377df7afd46c08

      How to Reproduce

      GridFSUploadOptions options = new GridFSUploadOptions()
                      .chunkSizeBytes(chunkSize)
                      .metadata(metadata);
      
      var stream = gridFSBucket().openUploadStream(new BsonObjectId(fileId), filename, options);
      stream.write(new byte[] {1,2,3});
      stream.close();  // stores file and sets closed = true
      stream.close();  // with 4.8 ignores closed flag and tries to store again

      Additional Background

      Please provide any additional background information that may be helpful in diagnosing the bug.

            Assignee:
            jeff.yemin@mongodb.com Jeffrey Yemin
            Reporter:
            konradend@gmail.com Konrad Endruszkiewicz
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: