azure-sdk-for-java icon indicating copy to clipboard operation
azure-sdk-for-java copied to clipboard

[BUG]BlobServiceClientBuilder’s buildClient method does not return or terminate the thread.

Open abhishekpankaj54 opened this issue 1 month ago • 4 comments

Describe the bug When I run the below line of code it does not return any thing(exception/logs or etc) and it exits the calling thread. BlobServiceClient blobServiceClient = (new BlobServiceClientBuilder()).endpoint(endpoint).credential(credential).buildClient();

Means it does not come back and releases the thread.

How did I verify this? I placed the line inside a try block and added a log statement after the call, but it never threw an exception and didn’t even write the logs.

Exception or Stack Trace No error /exception

To Reproduce use the below code:

public BlobBatchClient getBlobBatchClient(String storageAccountName) {
        log.debug("DEBUG_LOG inside getBlobBatchClient storageAccountName: {}",storageAccountName);
        StorageAccount storageAccount = getStorageAccountByName(storageAccountName);

        log.debug("DEBUG_LOG after  getStorageAccountByName");
        if (storageAccount !=null)
        {
            if (storageAccount.getKeys() != null)
            {
                log.debug("DEBUG_LOG inside getBlobBatchClient and checking keys{}",storageAccount.getKeys().get(0).value());
            }
            else {
                log.debug("DEBUG_LOG inside getBlobBatchClient storageAccount.getKeys() is null");
            }

        }
        else
        {
            log.debug("DEBUG_LOG inside getBlobBatchClient storageAccount is null");
        }
        String endpointString;
        if (getCloudProvider() == Provider.AZURE_GOV) {
            endpointString = ENDPOINTGOV_STRING;
        } else
            endpointString = ENDPOINT_STRING;
        String endpoint = String.format(Locale.ROOT, endpointString, storageAccountName);
        log.debug("DEBUG_LOG inside getBlobBatchClient endpoint{}",endpoint);
        StorageSharedKeyCredential credential = new StorageSharedKeyCredential(storageAccountName, storageAccount.getKeys().get(0).value());
        log.debug("DEBUG_LOG after  getStorageAccountByName credential{}",credential.getAccountName());
        BlobServiceClient blobServiceClient=null;
        try {
           
----------------till this it works---------------- 
            blobServiceClient = (new BlobServiceClientBuilder()).endpoint(endpoint).credential(credential).buildClient();  --------> when it reaches here no output and calling thread gets exit.
            log.debug("DEBUG_LOG after  getStorageAccountByName blobServiceClient{}", credential.getAccountName());
        } catch (Exception e) {
            log.debug("DEBUG_LOG inside getBlobBatchClient inside catch msg : {}",e.getMessage());
        }
        log.debug("DEBUG_LOG inside getBlobBatchClient before return");
        return new BlobBatchClientBuilder(blobServiceClient).buildClient();

    }

Code Snippet

public BlobBatchClient getBlobBatchClient(String storageAccountName) {
        log.debug("DEBUG_LOG inside getBlobBatchClient storageAccountName: {}",storageAccountName);
        StorageAccount storageAccount = getStorageAccountByName(storageAccountName);

        log.debug("DEBUG_LOG after  getStorageAccountByName");
        if (storageAccount !=null)
        {
            if (storageAccount.getKeys() != null)
            {
                log.debug("DEBUG_LOG inside getBlobBatchClient and checking keys{}",storageAccount.getKeys().get(0).value());
            }
            else {
                log.debug("DEBUG_LOG inside getBlobBatchClient storageAccount.getKeys() is null");
            }

        }
        else
        {
            log.debug("DEBUG_LOG inside getBlobBatchClient storageAccount is null");
        }
        String endpointString;
        if (getCloudProvider() == Provider.AZURE_GOV) {
            endpointString = ENDPOINTGOV_STRING;
        } else
            endpointString = ENDPOINT_STRING;
        String endpoint = String.format(Locale.ROOT, endpointString, storageAccountName);
        log.debug("DEBUG_LOG inside getBlobBatchClient endpoint{}",endpoint);
        StorageSharedKeyCredential credential = new StorageSharedKeyCredential(storageAccountName, storageAccount.getKeys().get(0).value());
        log.debug("DEBUG_LOG after  getStorageAccountByName credential{}",credential.getAccountName());
        BlobServiceClient blobServiceClient=null;
        try {
           
**----------------till this it works----------------** ****
            blobServiceClient = (new BlobServiceClientBuilder()).endpoint(endpoint).credential(credential).buildClient();  --------> when it reaches here no output and calling thread gets exit.
            log.debug("DEBUG_LOG after  getStorageAccountByName blobServiceClient{}", credential.getAccountName());
        } catch (Exception e) {
            log.debug("DEBUG_LOG inside getBlobBatchClient inside catch msg : {}",e.getMessage());
        }
        log.debug("DEBUG_LOG inside getBlobBatchClient before return");
        return new BlobBatchClientBuilder(blobServiceClient).buildClient();

    }

Expected behavior Calling the this line blobServiceClient = (new BlobServiceClientBuilder()).endpoint(endpoint).credential(credential).buildClient(); should return either data or null or error or exception

Screenshots NA

Setup (please complete the following information):

  • OS: [e.g. iOS] :SUSE
  • IDE: [e.g. IntelliJ]
  • Library/Libraries: Azure SDK
  • Java version: [e.g. 8] java 17
  • App Server/Environment:Azure
  • Frameworks: [e.g. Spring Boot, Micronaut, Quarkus, etc] Spring Boot
  • Azure-storage-common: 12.17
  • Azure-storage-blob:12:30

If you suspect a dependency version mismatch (e.g. you see NoClassDefFoundError, NoSuchMethodError or similar), please check out Troubleshoot dependency version conflict article first. If it doesn't provide solution for the problem, please provide:

  • verbose dependency tree (mvn dependency:tree -Dverbose)
  • exception message, full stack trace, and any available logs

Additional context Add any other context about the problem here.

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

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

abhishekpankaj54 avatar Dec 11 '25 13:12 abhishekpankaj54

@browndav-msft @gunjansingh-msft @ibrandes @kyleknap @seanmcc-msft

github-actions[bot] avatar Dec 11 '25 13:12 github-actions[bot]

Thank you for your feedback. Tagging and routing to the team member best able to assist.

github-actions[bot] avatar Dec 11 '25 13:12 github-actions[bot]

Hi @abhishekpankaj54,

I wasn't able to reproduce your issue with the code sample you provided. Could you attach your custom logs from that snippet for further investigation? Additionally, please enable SDK HTTP logging so we can verify that the first service call getAccountInfoWithResponse is not hanging and that token acquisition is not timing out.

ibrandes avatar Dec 11 '25 18:12 ibrandes

I found the below results with below scenario:

1 When I use the below versions of dependencies we got the error <groupId>com.azure</groupId> <artifactId>azure-storage-blob-batch</artifactId> 12.26.0 <groupId>com.azure</groupId> <artifactId>azure-core-http-netty</artifactId> and i do not have explicit com.azure:azure-storage-blob dependency added in my pom

Basically azure-storage-blob-batch 12.26 uses the zure-storage-blob:jar:12.30.0 as Compile Dependencies so below are the version used in my sample program . com.azure:azure-storage-blob-batch:jar:12.26.0:compile com.azure:azure-storage-blob:jar:12.30.0:compile //////////////////////////////////////////////////////////////////////////////////// Sample program import com.azure.storage.blob.BlobServiceClient; import com.azure.storage.blob.BlobServiceClientBuilder; import com.azure.storage.blob.batch.BlobBatchClient; import com.azure.storage.blob.batch.BlobBatchClientBuilder; import com.azure.storage.common.StorageSharedKeyCredential; import lombok.extern.slf4j.Slf4j; import org.slf4j.Logger; import org.slf4j.LoggerFactory;

@Slf4j public class Main { public static void main(String[] args) throws Exception { Main Obj=new Main(); Obj.getBlobBatchClient("env39frankfurt"); } public BlobBatchClient getBlobBatchClient(String storageAccountName) { log.debug("DEBUG_LOG inside getBlobBatchClient");

    // 1) Compose the endpoint based on cloud
    final String endpointString = "https://%s.blob.core.windows.net";

    // String storageAccountName = "<your-storage-account-name>";
    String accountKey = "sffsdfsgssrfggfdddggrdfhhKn4NUpWF7gaOJv4Hadfdtrddfdfdfdfdfdfdfdfdfdf2g==";
   
    String endpoint = String.format("https://%s.blob.core.windows.net", storageAccountName);

    // 1. Create Shared Key Credential
    StorageSharedKeyCredential credential = new StorageSharedKeyCredential(storageAccountName, accountKey);
    log.debug("DEBUG_LOG inside credential {}",credential);
    // 2. Build BlobServiceClient
    //HttpClient httpClient = new NettyAsyncHttpClientBuilder().build();
    BlobServiceClient blobServiceClient = new BlobServiceClientBuilder()
            .endpoint(endpoint)
            .credential(credential)
            .buildClient();
    log.debug("DEBUG_LOG inside blobServiceClient {}",blobServiceClient.getAccountInfo());
    return new BlobBatchClientBuilder(blobServiceClient).buildClient();
}

}

\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
ERROR: 16:44:13.569 [main] DEBUG org.example.Main - DEBUG_LOG inside getBlobBatchClient 16:44:13.614 [main] DEBUG com.azure.core.implementation.ReflectionUtils - Attempting to use java.lang.invoke package to handle reflection. 16:44:13.624 [main] DEBUG com.azure.core.implementation.ReflectionUtils - Successfully used java.lang.invoke package to handle reflection. 16:44:13.629 [main] DEBUG org.example.Main - DEBUG_LOG inside credential com.azure.storage.common.StorageSharedKeyCredential@475530b9 16:44:13.850 [main] ERROR com.azure.core.implementation.util.Providers - A request was made to load the default HttpClient provider but one could not be found on the classpath. If you are using a dependency manager, consider including a dependency on azure-core-http-netty or azure-core-http-okhttp. Depending on your existing dependencies, you have the choice of Netty or OkHttp implementations. Additionally, refer to https://aka.ms/azsdk/java/docs/custom-httpclient to learn about writing your own implementation. java.lang.IllegalStateException: A request was made to load the default HttpClient provider but one could not be found on the classpath. If you are using a dependency manager, consider including a dependency on azure-core-http-netty or azure-core-http-okhttp. Depending on your existing dependencies, you have the choice of Netty or OkHttp implementations. Additionally, refer to https://aka.ms/azsdk/java/docs/custom-httpclient to learn about writing your own implementation. at com.azure.core.implementation.util.Providers.create(Providers.java:111) at com.azure.core.implementation.http.HttpClientProviders.createInstance(HttpClientProviders.java:58) at com.azure.core.http.HttpClient.createDefault(HttpClient.java:61) at com.azure.core.http.HttpClient.createDefault(HttpClient.java:51) at com.azure.core.http.HttpPipelineBuilder.build(HttpPipelineBuilder.java:88) at com.azure.storage.blob.implementation.util.BuilderHelper.buildPipeline(BuilderHelper.java:153) at com.azure.storage.blob.BlobServiceClientBuilder.constructPipeline(BlobServiceClientBuilder.java:152) at com.azure.storage.blob.BlobServiceClientBuilder.buildClient(BlobServiceClientBuilder.java:126) at org.example.Main.getBlobBatchClient(Main.java:39) at org.example.Main.main(Main.java:18) Exception in thread "main" java.lang.IllegalStateException: A request was made to load the default HttpClient provider but one could not be found on the classpath. If you are using a dependency manager, consider including a dependency on azure-core-http-netty or azure-core-http-okhttp. Depending on your existing dependencies, you have the choice of Netty or OkHttp implementations. Additionally, refer to https://aka.ms/azsdk/java/docs/custom-httpclient to learn about writing your own implementation. at com.azure.core.implementation.util.Providers.create(Providers.java:111) at com.azure.core.implementation.http.HttpClientProviders.createInstance(HttpClientProviders.java:58) at com.azure.core.http.HttpClient.createDefault(HttpClient.java:61) at com.azure.core.http.HttpClient.createDefault(HttpClient.java:51) at com.azure.core.http.HttpPipelineBuilder.build(HttpPipelineBuilder.java:88) at com.azure.storage.blob.implementation.util.BuilderHelper.buildPipeline(BuilderHelper.java:153) at com.azure.storage.blob.BlobServiceClientBuilder.constructPipeline(BlobServiceClientBuilder.java:152) at com.azure.storage.blob.BlobServiceClientBuilder.buildClient(BlobServiceClientBuilder.java:126) at org.example.Main.getBlobBatchClient(Main.java:39) at org.example.Main.main(Main.java:18)

2 When I use the below versions of dependencies we got the error <groupId>com.azure</groupId> <artifactId>azure-storage-blob-batch</artifactId> 12.26.0 and i do not have explicit com.azure:azure-storage-blob dependency added in my pom

Basically azure-storage-blob-batch 12.26 uses the zure-storage-blob:jar:12.30.0 as Compile Dependencies so below are the version used in my sample program . com.azure:azure-storage-blob-batch:jar:12.26.0:compile com.azure:azure-storage-blob:jar:12.30.0:compile

In this case i remove the netty exclusion from POM and added the below imports in my sample program import com.azure.core.http.HttpClient; import com.azure.core.http.netty.NettyAsyncHttpClientBuilder;

### and it worked.

3 I used the same as first scenario and only added the below dependency (NO netty and its import added /used)and it worked <groupId>com.azure</groupId> <artifactId>azure-storage-blob</artifactId> 12.26.0

com.azure:azure-storage-blob-batch:jar:12.26.0:compile com.azure:azure-storage-blob:jar:12.26.0:compile

-------------->

abhishekpankaj54 avatar Dec 12 '25 11:12 abhishekpankaj54

Customer resolved issue by adjusting dependencies.

ibrandes avatar Dec 14 '25 19:12 ibrandes