Azure / azure-storage-java

Microsoft Azure Storage Library for Java
https://docs.microsoft.com/en-us/java/api/overview/azure/storage
MIT License
189 stars 165 forks source link

BlobClient#upload not releasing file handles #586

Closed strangelookingnerd closed 1 year ago

strangelookingnerd commented 1 year ago

Which service(blob, file, queue, table) does this issue concern?

blob

Which version of the SDK was used?

12.22.3

What problem was encountered?

I'm trying to upload a file via FileInputStream using the BlobClient. The following example throws a FileSystemException concerning the file being used by another process. The stream is closed by the try-with-resource block so that does not seem to be an issue.

File file = new File("test.txt");
Files.write(file.toPath(), "Test".getBytes(Charset.defaultCharset()));

BlobContainerClient client = new BlobContainerClientBuilder() //
    .connectionString("connectionString") //
    .containerName("containerName") //
    .buildClient();

try (FileInputStream stream = new FileInputStream(file)) {
    client.getBlobClient("blobName").upload(stream, true);
}

Files.delete(file.toPath()); // throws java.nio.file.FileSystemException

Have you found a mitigation/solution?

Using BlobClient#uploadFromFile with the file instead of the FileInputStream works fine. However in my scenario I only have a FileInputStream that I want to upload.

strangelookingnerd commented 1 year ago

Moved to https://github.com/Azure/azure-sdk-for-java/issues/35971