Azure / azure-sdk-for-java

This repository is for active development of the Azure SDK for Java. For consumers of the SDK we recommend visiting our public developer docs at https://docs.microsoft.com/java/azure/ or our versioned developer docs at https://azure.github.io/azure-sdk-for-java.
MIT License
2.33k stars 1.98k forks source link

[BUG] block()/blockFirst()/blockLast() are blocking, which is not supported in thread default-nioEventLoopGroup-1 for BlobClientBase.exists() #42268

Open loicmathieu opened 1 week ago

loicmathieu commented 1 week ago

Describe the bug

Exception when calling BlobClientBase.exists().

Exception or Stack Trace

java.lang.IllegalStateException: block()/blockFirst()/blockLast() are blocking, which is not supported in thread default-nioEventLoopGroup-1-5
    at reactor.core.publisher.BlockingSingleSubscriber.blockingGet(BlockingSingleSubscriber.java:87)
    at reactor.core.publisher.Mono.block(Mono.java:1779)
    at com.azure.storage.common.implementation.StorageImplUtils.blockWithOptionalTimeout(StorageImplUtils.java:146)
    at com.azure.storage.blob.specialized.BlobClientBase.existsWithResponse(BlobClientBase.java:501)
    at com.azure.storage.blob.specialized.BlobClientBase.exists(BlobClientBase.java:479)

To Reproduce Using the following code in a Micronaut controller with file upload. The error shows up only for files of a certain size (more than 1MB).

Code Snippet

    private boolean exists(String path) {
        try {
            BlobClient blobClient = this.blobContainerClient.getBlobClient(path);
            return blobClient.exists();
        } catch (BlobStorageException e) {
            return false;
        }
    }

Setup (please complete the following information):

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

github-actions[bot] commented 1 week ago

@ibrahimrabab @ibrandes @kyleknap @seanmcc-msft

github-actions[bot] commented 1 week ago

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

loicmathieu commented 1 week ago

I found a workaround but it's not pretty:

Something like that:

private final ExecutorService executorService = Executors.newSingleThreadExecutor();

    private <T> T block(Mono<T> mono) {
        try {
            return executorService.submit(() -> mono.blockOptional().orElse(null)).get();
        } catch (InterruptedException | ExecutionException e) {
            throw new RuntimeException(e);
        }
    }
loicmathieu commented 1 week ago

It not only happens for exist() but for any method of the BlobClient.