[英]Deploying Azure App Service Webjob Using .Net 6 Fails to Start "Failed to bind to address http://127.0.0.1:5000: address already in use"
I ran into an issue while migrating an Azure app service from.Net Core 5 to 6 while also updating the stack configuration in Azure Portal to use.Net version ".Net 6 (LTS)".我在将 Azure 应用程序服务从 .Net Core 5 迁移到 6 时遇到问题,同时还更新 Azure 门户中的堆栈配置以使用 .Net 版本“.Net 6 (LTS)”。 The app service only contains continuous webjobs that process service bus messages.
应用服务仅包含处理服务总线消息的连续 Web 作业。 Locally, the webjob project runs fine but when deployed to Azure it fails to start.
在本地,webjob 项目运行良好,但部署到 Azure 时无法启动。 In Kudu tools I'm presented with an error:
在 Kudu 工具中,我遇到了一个错误:
[01/03/2023 18:21:32 > 1b0f90: ERR ] Unhandled exception. System.IO.IOException: Failed to bind to address http://127.0.0.1:5000: address already in use.
[01/03/2023 18:21:32 > 1b0f90: ERR ] ---> Microsoft.AspNetCore.Connections.AddressInUseException: Only one usage of each socket address (protocol/network address/port) is normally permitted.
[01/03/2023 18:21:32 > 1b0f90: ERR ] ---> System.Net.Sockets.SocketException (10048): Only one usage of each socket address (protocol/network address/port) is normally permitted.
Eventually I am able to get past the error by applying the app setting AS.NETCORE_URLS=http://localhost:5001
to the app service, and applying the same app setting every.Net Core 6 app service running web jobs in the same app service plan except I have to increment the port to something different.最终,我能够通过将应用程序设置
AS.NETCORE_URLS=http://localhost:5001
应用于应用程序服务并应用相同的应用程序设置来克服错误。每个.Net Core 6 应用程序服务在同一应用程序中运行 web 个作业服务计划,除了我必须将端口增加到不同的东西。 This does not seem to be a problem with non-webjob applications, and only occurs when I configure the app service stack to ".Net 6 (LTS)" in Azure Portal.这似乎不是非 webjob 应用程序的问题,只有当我在 Azure 门户中将应用程序服务堆栈配置为“.Net 6 (LTS)”时才会出现。
My question is: Is there another workaround to this issue?我的问题是:这个问题还有其他解决方法吗? I find adding unique port assignments to every webjob running.Net 6 to be a cumbersome and not ideal, and this issue will exist as a serious gotcha for future development.
我发现为每个运行 .Net 6 的 webjob 添加唯一的端口分配是一件麻烦且不理想的事情,而且这个问题将作为未来开发的一个严重陷阱而存在。
Here is the dependencies I am pulling in:这是我引入的依赖项:
Azure.Messaging.ServiceBus Version=7.11.0
Microsoft.Azure.WebJobs Version=3.0.32
Microsoft.ApplicationInsights.AspNetCore Version=2.21.0
Microsoft.ApplicationInsights.NLogTarget Version=2.21.0
Microsoft.Azure.Services.AppAuthentication Version=1.6.2
Microsoft.Azure.WebJobs.Extensions Version=4.0.1
Microsoft.Azure.WebJobs.Extensions.ServiceBus Version=5.3.0
Microsoft.Azure.WebJobs.Extensions.Storage Version=5.0.1
NLog Version=5.0.4
NLog.Targets.Seq Version=2.1.0
NLog.Web.AspNetCore Version=5.1.4
To reproduce:重现:
Now when you go to view the webjobs in Azure Portal you will see that the job is stuck in a restart cycle.现在,当您 go 查看 Azure 门户中的 web 作业时,您会看到该作业卡在重启周期中。
The problem seems to be around setting the stack settings version to ".Net 6 (LTS)".问题似乎与将堆栈设置版本设置为“.Net 6 (LTS)”有关。 From this article it seems that this setting makes the app service Run Kestrel with YARP, I'm guessing the feature parity is not 1:1 with the previous stack.
从这篇文章看来,此设置似乎使应用程序服务使用 YARP 运行 Kestrel,我猜测功能奇偶校验与之前的堆栈不是 1:1。
I have created 2 .NET Core 6
Applications and deployed to Azure Web Jobs
in same Azure App Service
.我创建了 2
.NET Core 6
应用程序并部署到Azure Web Jobs
相同的Azure App Service
中的工作。
Always On
option in App Service
=> Configuration
=> General Settings
to ensure WebJobs
are running Continuously.App Service
=> Configuration
=> General Settings
中启用Always On
选项以确保WebJobs
持续运行。 .NET 6
..NET 6
。 Now when you go to view the webjobs in Azure Portal you will see that the job is stuck in a restart cycle.
现在,当您 go 查看 Azure 门户中的 web 作业时,您会看到该作业卡在重启周期中。
Yes, even I got stuck with the same issue.是的,即使我也遇到了同样的问题。 The
WebJob
which I have published 2nd is showing the Pending Restart
status.我第二次发布的
WebJob
显示Pending Restart
状态。
When I click on the Logs, I can see the below error is Logged.当我点击日志时,我可以看到记录了以下错误。
Make sure that you are setting a connection string named >`AzureWebJobsDashboard` in your Microsoft Azure Website >configuration by using the following format >`DefaultEndpointsProtocol=https;AccountName=**NAME**;Account>Key=**KEY**` pointing to the Microsoft Azure Storage account where >the Microsoft Azure WebJobs Runtime logs are stored.
WebJobs
and Storage Account
.WebJobs
和 Storage Account
。 My Program.cs
file:我的
Program.cs
文件:
// See https://aka.ms/new-console-template for more information
using System.Threading.Tasks;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
namespace WebJobApp
{
class Program
{
static async Task Main()
{
var builder = new HostBuilder();
builder.UseEnvironment(EnvironmentName.Development);
builder.ConfigureWebJobs(b =>
{
b.AddAzureStorageCoreServices();
b.AddAzureStorageQueues();
});
builder.ConfigureLogging((context, b) =>
{
b.AddConsole();
});
var host = builder.Build();
using (host)
{
await host.RunAsync();
}
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.