Azure Cosmos DB Trigger Function uploading file to storage account fails with ClosedChannelException Exception

Anil Patnagere Jayanna 11 Reputation points
2022-09-30T18:04:35.757+00:00

Hi,
I'm writing azure cosmos DB trigger function using Java, which fetches the data from the cosmos DB collection whenever there is a change made in the database and writes the data into azure storage blob container. Below is the cosmos db trigger function code and blobClient.uploadFromFile call fails with ClosedChannelException Exception.
I'm not able to figure out the issue, any help on this would be appreciated.

Thanks
Anil

blobClient.uploadFromFile(file.getAbsolutePath(),true);

Error:-
Uploading to Blob storage as blob:
https://*************.blob.core.windows.net/*********-dev-storage-container/blockedUrls.json

Ufile.getAbsolutePath():/************/target/azure-functions/azure-function-examples-1620635048938/blockedUrls.json
Executed 'Functions.cosmosDBtoRedis' (Failed, Id=5a6d3209-c83c-4588-99ba-577ca73d736c, Duration=45163ms)
System.Private.CoreLib: Exception while executing function: Functions.cosmosDBtoRedis. System.Private.CoreLib: Result: Failure
Exception: ClosedChannelException:
Stack: java.lang.reflect.InvocationTargetException
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at com.microsoft.azure.functions.worker.broker.JavaMethodInvokeInfo.invoke(JavaMethodInvokeInfo.java:22)
at com.microsoft.azure.functions.worker.broker.EnhancedJavaMethodExecutorImpl.execute(EnhancedJavaMethodExecutorImpl.java:55)
at com.microsoft.azure.functions.worker.broker.JavaFunctionBroker.invokeMethod(JavaFunctionBroker.java:61)
at com.microsoft.azure.functions.worker.handler.InvocationRequestHandler.execute(InvocationRequestHandler.java:33)
at com.microsoft.azure.functions.worker.handler.InvocationRequestHandler.execute(InvocationRequestHandler.java:10)
at com.microsoft.azure.functions.worker.handler.MessageHandler.handle(MessageHandler.java:45)
at com.microsoft.azure.functions.worker.JavaWorkerClient$StreamingMessagePeer.lambda$onNext$0(JavaWorkerClient.java:92)
at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
at java.base/java.lang.Thread.run(Thread.java:829)
Caused by: reactor.core.Exceptions$ReactiveException: java.nio.channels.ClosedChannelException
at reactor.core.Exceptions.propagate(Exceptions.java:392)
at reactor.core.publisher.BlockingSingleSubscriber.blockingGet(BlockingSingleSubscriber.java:97)
at reactor.core.publisher.Mono.block(Mono.java:1707)
at com.azure.storage.common.implementation.StorageImplUtils.blockWithOptionalTimeout(StorageImplUtils.java:128)
at com.azure.storage.blob.BlobClient.uploadFromFileWithResponse(BlobClient.java:389)
at com.azure.storage.blob.BlobClient.uploadFromFile(BlobClient.java:361)
at com.azure.storage.blob.BlobClient.uploadFromFile(BlobClient.java:334)
at com.expleo.solutions.protectus.api.CosmosDBTriggerHandler.cosmosDbProcessor(CosmosDBTriggerHandler.java:35)
... 16 more
Suppressed: java.lang.Exception: #block terminated with an error
at reactor.core.publisher.BlockingSingleSubscriber.blockingGet(BlockingSingleSubscriber.java:99)
... 22 more
Caused by: java.nio.channels.ClosedChannelException
at io.netty.channel.AbstractChannel$AbstractUnsafe.newClosedChannelException(AbstractChannel.java:957)
at io.netty.channel.AbstractChannel$AbstractUnsafe.ensureOpen(AbstractChannel.java:976)
at io.netty.channel.epoll.AbstractEpollChannel$AbstractEpollUnsafe.connect(AbstractEpollChannel.java:590)
at io.netty.channel.DefaultChannelPipeline$HeadContext.connect(DefaultChannelPipeline.java:1342)
at io.netty.channel.AbstractChannelHandlerContext.invokeConnect(AbstractChannelHandlerContext.java:548)
at io.netty.channel.AbstractChannelHandlerContext.connect(AbstractChannelHandlerContext.java:533)
at io.netty.channel.AbstractChannelHandlerContext.connect(AbstractChannelHandlerContext.java:517)
at io.netty.channel.AbstractChannelHandlerContext.connect(AbstractChannelHandlerContext.java:457)
at io.netty.channel.DefaultChannelPipeline.connect(DefaultChannelPipeline.java:942)
at io.netty.channel.AbstractChannel.connect(AbstractChannel.java:217)
at reactor.netty.transport.TransportConnector.lambda$doConnect$8(TransportConnector.java:181)
at io.netty.util.concurrent.AbstractEventExecutor.safeExecute(AbstractEventExecutor.java:164)
at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:469)
at io.netty.channel.epoll.EpollEventLoop.run(EpollEventLoop.java:384)
at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:986)
at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74)
at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
... 1 more
.

Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
4,248 questions
Azure Storage Accounts
Azure Storage Accounts
Globally unique resources that provide access to data management services and serve as the parent namespace for the services.
2,683 questions
Azure Cosmos DB
Azure Cosmos DB
An Azure NoSQL database service for app development.
1,440 questions
{count} vote

1 answer

Sort by: Most helpful
  1. Anil Patnagere Jayanna 11 Reputation points
    2022-10-04T16:14:19.607+00:00

    Thanks Muthu, for the links (https://github.com/Azure/azure-sdk-for-java/issues/25631#issuecomment-1021694209 which refers to https://stackoverflow.com/questions/70176728/basic-blob-download-fails-using-com-azure-storage-blob-package-with-java-nio-cha/70192990). That helped.

    Problem was with the dependencies. I added netty libraries to exclusion list and added old version of netty dependencies. It worked fine.

    <!-- https://mvnrepository.com/artifact/io.netty/netty-codec-http -->  
            <dependency>  
                <groupId>io.netty</groupId>  
                <artifactId>netty-codec-http</artifactId>  
                <version>4.1.70.Final</version>  
            </dependency>  
            <!-- https://mvnrepository.com/artifact/io.netty/netty-codec-http2 -->  
            <dependency>  
                <groupId>io.netty</groupId>  
                <artifactId>netty-codec-http2</artifactId>  
                <version>4.1.70.Final</version>  
            </dependency>  
            <!-- https://mvnrepository.com/artifact/io.netty/netty-common -->  
            <dependency>  
                <groupId>io.netty</groupId>  
                <artifactId>netty-common</artifactId>  
                <version>4.1.70.Final</version>  
            </dependency>    
    <!-- https://mvnrepository.com/artifact/io.projectreactor/reactor-core -->  
    <dependency>  
    <groupId>io.projectreactor</groupId>  
    <artifactId>reactor-core</artifactId>  
    <version>3.4.14</version>  
    </dependency>  
              
    <dependency>  
        <groupId>com.azure</groupId>  
        <artifactId>azure-core-http-netty</artifactId>  
        <version>1.11.9</version>  
                <exclusions>  
                    <exclusion>  <!-- declare the exclusion here -->  
                        <groupId>io.netty</groupId>  
                        <artifactId>netty-codec-http</artifactId>  
                    </exclusion>  
                    <exclusion>  <!-- declare the exclusion here -->  
                        <groupId>io.netty</groupId>  
                        <artifactId>netty-codec-http2</artifactId>  
                    </exclusion>  
                    <exclusion>  <!-- declare the exclusion here -->  
                        <groupId>io.netty</groupId>  
                        <artifactId>netty-common</artifactId>  
                    </exclusion>  
                </exclusions>   
    </dependency>   
      <dependency>  
                <groupId>com.azure</groupId>  
                <artifactId>azure-storage-blob</artifactId>  
                <version>12.14.2</version>  
                <exclusions>  
                    <exclusion>  <!-- declare the exclusion here -->  
                        <groupId>io.netty</groupId>  
                        <artifactId>netty-codec-http</artifactId>  
                    </exclusion>  
                    <exclusion>  <!-- declare the exclusion here -->  
                        <groupId>io.netty</groupId>  
                        <artifactId>netty-codec-http2</artifactId>  
                    </exclusion>  
                    <exclusion>  <!-- declare the exclusion here -->  
                        <groupId>io.netty</groupId>  
                        <artifactId>netty-common</artifactId>  
                    </exclusion>  
                    <exclusion>  <!-- declare the exclusion here -->  
                        <groupId>io.projectreactor</groupId>  
                        <artifactId>reactor-core</artifactId>  
                    </exclusion>  
                </exclusions>   
            </dependency>  
    
    1 person found this answer helpful.