Skip to content

Move check for previous value of "closed" outside of lambda #1058

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -138,12 +138,14 @@ public void write(final byte[] b, final int off, final int len) {

@Override
public void close() {
withLock(closeLock, () -> {
if (closed) {
return;
}
boolean alreadyClosed = withLock(closeLock, () -> {
boolean prevClosed = closed;
closed = true;
return prevClosed;
});
if (alreadyClosed) {
return;
}
writeChunk();
GridFSFile gridFSFile = new GridFSFile(fileId, filename, lengthInBytes, chunkSizeBytes, new Date(),
metadata);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ class GridFSBucketSmokeTestSpecification extends FunctionalSpecification {
def outputStream = gridFSBucket.openUploadStream('myFile')
outputStream.write(contentBytes)
outputStream.close()
outputStream.close() // check for close idempotency
fileId = outputStream.getObjectId()
}

Expand Down