[JAVA-4821] Close operation on GridFsUploadStream is not idempotent Created: 30/Nov/22  Updated: 28/Oct/23  Resolved: 05/Dec/22

Status: Closed
Project: Java Driver
Component/s: GridFS
Affects Version/s: 4.8.0
Fix Version/s: 4.8.1

Type: Bug Priority: Minor - P4
Reporter: Konrad Endruszkiewicz Assignee: Jeffrey Yemin
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Documentation Changes: Not Needed

 Description   

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.



 Comments   
Comment by Githook User [ 05/Dec/22 ]

Author:

{'name': 'Jeff Yemin', 'email': 'jeff.yemin@mongodb.com', 'username': 'jyemin'}

Message: Move check for previous value of "closed" outside of lambda (#1058)

JAVA-4821
Branch: 4.8.x
https://github.com/mongodb/mongo-java-driver/commit/ac2c6329ea238ff07453acb9e505b6836660bc41

Comment by Githook User [ 05/Dec/22 ]

Author:

{'name': 'Jeff Yemin', 'email': 'jeff.yemin@mongodb.com', 'username': 'jyemin'}

Message: Move check for previous value of "closed" outside of lambda (#1058)

JAVA-4821
Branch: master
https://github.com/mongodb/mongo-java-driver/commit/41b9ce3afa3023d8884f1b5413a437295ba1560d

Comment by Jeffrey Yemin [ 30/Nov/22 ]

Thanks for finding this. Working on a fix now.

Generated at Thu Feb 08 09:03:03 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.