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.