名称或服务未知 - Azure 中的间歇性错误
Name or Service not known - intermittent error in Azure
我有一个 TimerTrigger,它以相对较高的速率调用我自己的 Azure Functions - 每秒几次。它没有经过压力测试。每次调用只需要100ms,测试目的不是压力测试。
对我自己的端点的调用在 10000 次中运行了大约 9999 次,但偶尔我会收到以下错误:
System.Net.Http.HttpRequestException: Name or service not known (app.mycustomdomain.com:443)
---> System.Net.Sockets.SocketException (0xFFFDFFFF): Name or service not known
at System.Net.Sockets.Socket.AwaitableSocketAsyncEventArgs.ThrowException(SocketError error, CancellationToken cancellationToken)
我在上面的错误消息中用“app.mycustomdomain.com”替换了我的实际域。它是一个自定义域,设置为使用 CNAME 指向 Azure Function App。
Function App 未检测到 Azure 门户中的任何停机时间,我启用了 Application Insights 并且没有看到任何错误。所以我假设问题出在呼叫者一方,而呼叫从未真正发生过。
这个错误说明了什么?我该如何缓解这个问题?
对于你的第二个问题——缓解这个问题,一个选择当然是使用像 Polly. High level you create a policy, e.g. for a simple retry:
这样的库来构建重试
var myPolicy = Policy
.Handle<SomeExceptionType>()
.Retry(3);
这将重试 3 次,要使用您可以调用 Execute 的同步或异步版本的策略:
await myPolicy.ExecuteAsync(async () =>
{
//do stuff that might fail up to three times
});
More complete samples are available
这个库对其他方法有很多支持,例如延迟、指数延迟等
我有一个 TimerTrigger,它以相对较高的速率调用我自己的 Azure Functions - 每秒几次。它没有经过压力测试。每次调用只需要100ms,测试目的不是压力测试。
对我自己的端点的调用在 10000 次中运行了大约 9999 次,但偶尔我会收到以下错误:
System.Net.Http.HttpRequestException: Name or service not known (app.mycustomdomain.com:443)
---> System.Net.Sockets.SocketException (0xFFFDFFFF): Name or service not known
at System.Net.Sockets.Socket.AwaitableSocketAsyncEventArgs.ThrowException(SocketError error, CancellationToken cancellationToken)
我在上面的错误消息中用“app.mycustomdomain.com”替换了我的实际域。它是一个自定义域,设置为使用 CNAME 指向 Azure Function App。
Function App 未检测到 Azure 门户中的任何停机时间,我启用了 Application Insights 并且没有看到任何错误。所以我假设问题出在呼叫者一方,而呼叫从未真正发生过。
这个错误说明了什么?我该如何缓解这个问题?
对于你的第二个问题——缓解这个问题,一个选择当然是使用像 Polly. High level you create a policy, e.g. for a simple retry:
这样的库来构建重试var myPolicy = Policy
.Handle<SomeExceptionType>()
.Retry(3);
这将重试 3 次,要使用您可以调用 Execute 的同步或异步版本的策略:
await myPolicy.ExecuteAsync(async () =>
{
//do stuff that might fail up to three times
});
More complete samples are available
这个库对其他方法有很多支持,例如延迟、指数延迟等