Azure Function 访问 Blob 时超时

huangapple go评论81阅读模式
英文:

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.

英文:

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.

答案1

得分: 2

以下是要翻译的内容:

"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."

英文:

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.

答案2

得分: -1

以下是已经翻译好的部分:

"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."

英文:

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.

huangapple
  • 本文由 发表于 2020年8月11日 23:11:01
  • 转载请务必保留本文链接:https://go.coder-hub.com/63361138.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定