Skip to content

[BUG] BlobClient.download fails with "Connection reset by peer" for large files #21066

Description

@jgmpzman

Describe the bug
We are using the azure java sdk in our product code. Part of the functionality that we need to support is downloading a file from azure. This works consistently for files under 10 Gb. There are issues when trying to download block blobs that are greater than 10 Gb, especially around 90 Gb. The api has no problem uploading the 90 Gb file, it is just the downloading portion that seems to fail frequently. It will occasionally work, but it seems to fail much more than it succeeds. I am wondering if perhaps there is a better api method that should be used for larger files, any help would be greatly appreciated?

Exception or Stack Trace
2021-04-29 20:32:49 246 [main] ERROR com.jgm.AzureFileDownload - Error while trying to download the file=/home/kompuser/90gb.txt
reactor.core.Exceptions$ReactiveException: io.netty.channel.unix.Errors$NativeIoException: readAddress(..) failed: Connection reset by peer
at reactor.core.Exceptions.propagate(Exceptions.java:393)
at reactor.core.publisher.BlockingSingleSubscriber.blockingGet(BlockingSingleSubscriber.java:97)
at reactor.core.publisher.Mono.block(Mono.java:1680)
at com.azure.storage.common.implementation.StorageImplUtils.blockWithOptionalTimeout(StorageImplUtils.java:99)
at com.azure.storage.blob.specialized.BlobClientBase.downloadWithResponse(BlobClientBase.java:562)
at com.azure.storage.blob.specialized.BlobClientBase.download(BlobClientBase.java:522)
at com.jgm.AzureFileDownload.getObject(AzureFileDownload.java:41)
at com.jgm.AzureFileDownload.main(AzureFileDownload.java:61)
Suppressed: java.lang.Exception: #block terminated with an error
at reactor.core.publisher.BlockingSingleSubscriber.blockingGet(BlockingSingleSubscriber.java:99)
... 6 more
Caused by: io.netty.channel.unix.Errors$NativeIoException: readAddress(..) failed: Connection reset by peer

To Reproduce

  1. Upload a 90 Gb block blob file to azure (took about 75 minutes)
  2. Use BlobClient.download(FileOutputStream) to download the file

Code Snippet
A shorter variation of the code is here:

  public class AzureFileDownload {

    private static final Logger log = LoggerFactory.getLogger(AzureFileDownload.class);

    private final BlobContainerClient container;

    public AzureFileDownload(String bucketName, String accountName, String accountKey) {
        String endpoint = String.format(Locale.ROOT, "https://%s.blob.core.windows.net", accountName);
        this.container = createBlobServiceClient(new StorageSharedKeyCredential(accountName, accountKey), endpoint).getBlobContainerClient(bucketName);
    }

    private BlobClient createBlobClient(String key) {
        String encodedKey = Utility.urlEncode(key);     // Encode + and %
        return container.getBlobClient(encodedKey);
    }

    private BlobServiceClient createBlobServiceClient(StorageSharedKeyCredential credential, String endpoint) {
        return new BlobServiceClientBuilder().credential(credential).endpoint(endpoint).buildClient();
    }

    public void getObject(String key, File file) {
        try (OutputStream outputStream = new FileOutputStream(file)) {
            BlobClient blob = createBlobClient(key);
            blob.download(outputStream);
        } catch (Exception e) {
            log.error("Error while trying to download the file={}", file, e);
        }
    }

    public static void main(String[] args) {
        if (args.length < 5) {
            log.info("The following parameters are needed in order to run this code: {accountName} {bucketName} {accountKey} {fileKeyToDownload} {filePathToDownloadTo]");
            System.exit(0);
        }

        String accountName = args[0];
        String bucketName = args[1];
        String accountKey = args[2];
        String fileKey = args[3];
        File downloadTo = new File(args[4]);

        log.debug("bucketName={} accountName={}", bucketName, accountName);
        AzureFileDownload azureFileDownload = new AzureFileDownload(bucketName, accountName, accountKey);
        azureFileDownload.getObject(fileKey, downloadTo);
    }

Expected behavior
I would expect this call to be successful more than it fails.

Screenshots
If applicable, add screenshots to help explain your problem.

Setup (please complete the following information):

  • OS: MacOS BigSur 11.3 and CentOS Linux release 7.8.2003 (Core)
  • IDE : IntelliJ
  • 12.9.0

Additional context
Logs from one failed run set to DEBUG: https://pastebin.com/G3wXVQrw

Information Checklist
Kindly make sure that you have added all the following information above and checkoff the required fields otherwise we will treat the issuer as an incomplete report

  • [X ] Bug Description Added
  • [X ] Repro Steps Added
  • [X ] Setup information Added

Metadata

Metadata

Assignees

Labels

ClientThis issue points to a problem in the data-plane of the library.StorageStorage Service (Queues, Blobs, Files)customer-reportedIssues that are reported by GitHub users external to the Azure organization.questionThe issue doesn't require a change to the product in order to be resolved. Most issues start as that

Type

No type

Fields

No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions