schurterb
schurterb

Reputation: 53

Azure Function timeout when accessing Blob

I have encountered a strange problem when accessing an Azure Storage Blob from an Azure Function. I have a Function written in Java which is supposed to download some data from a Blob and then execute a PowerShell command. The PowerShell command can launch another Java application, which accesses the same Blob. I have this process working except for where the Function first downloads the Blob, which always gives a timeout while trying to get the size.

The weird thing is that the Java application launched by the PowerShell command uses the same code to download the Blob and can do so without any trouble at all.

Here is the relevant code snippet:

try {
    blob = new BlobClientBuilder().endpoint(connStr).buildClient();
    int dataSize = (int) blob.getProperties().getBlobSize(); // <- timeout occurs here
    ByteArrayOutputStream outputStream = new ByteArrayOutputStream(dataSize);
    blob.download(outputStream);
    outputStream.close();
    String result = new String(outputStream.toByteArray(), "UTF-8");
    return JsonParser.parseString(result).getAsJsonObject();
}
catch(Exception e) {
    System.out.println("ERROR: "+e.getMessage());
    e.printStackTrace();
    return null;
}

Some relevant info: The Blob is very small - only a few KB.
The same connection string is used in both cases.
The Blob is not the trigger for the function, but rather stores data for it.

EDIT

After getting better logs with a Log Analytics workspace, I found the timeout is being caused by a NoSuchMethodError.

java.lang.NoSuchMethodError: io.netty.handler.ssl.SslProvider.isAlpnSupported(Lio/netty/handler/ssl/SslProvider;)Z

I've seen this error before when I had the wrong version of netty-all-x.x.xFINAL.jar. Having already fixed this in the jars I upload with my code, I am now wondering where the Function gets libraries from other than what I include.

Upvotes: 2

Views: 1449

Answers (2)

SarangRN
SarangRN

Reputation: 140

One more solution is to find out the exact error by running azure in local environment. most of the time following error is misleading.

FailureException: ClassCastException: java.lang.NoSuchMethodError cannot be cast to java.lang.RuntimeExceptionStack: java.lang.reflect.InvocationTargetExceptionat sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)at

following link will help you to run and debug azure function in local.

https://learn.microsoft.com/en-us/azure/azure-functions/functions-create-maven-eclipse

most of the time the issues is also due to dependency jars conflicts as explained in previous post.

Upvotes: -1

schurterb
schurterb

Reputation: 53

Following the exception mentioned in the edit led me to this thread: https://github.com/Azure/azure-functions-java-worker/issues/381.

The issue was that the dependencies for the Function App itself were loading before my dependencies for my code and there is a conflict between them as mentioned here: https://github.com/Azure/azure-functions-java-worker/issues/365.

The solution was to set FUNCTIONS_WORKER_JAVA_LOAD_APP_LIBS = 1 in the Configuration settings of the Function App.

Upvotes: 2

Related Questions