简体   繁体   English

使用 .Net 6 部署 Azure App Service Webjob 无法启动“无法绑定到地址 http://127.0.0.1:5000:地址已在使用中”

[英]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:重现:

  1. Create two or more.Net Core 6 applications that only implement Webjobs.创建两个或多个仅实现 Webjobs 的 .Net Core 6 应用程序。 My Webjobs functions process Service Bus topic messages, not sure if this is important to reproduce.我的 Webjobs 函数处理服务总线主题消息,不确定重现这是否重要。
  2. Deploy the Webjob applications to the same App Service Plan将 Webjob 应用程序部署到相同的应用程序服务计划
  3. In the configuration blade settings tab for each web app make sure that the runtime stack is set to ".Net 6 (LTS)", keep the rest as default.在每个 web 应用程序的配置刀片设置选项卡中,确保运行时堆栈设置为“.Net 6 (LTS)”,将 rest 保留为默认值。

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中的工作。

在此处输入图像描述

  • Make sure to enable Always On option in App Service => Configuration => General Settings to ensure WebJobs are running Continuously.确保在App Service => Configuration => General Settings中启用Always On选项以确保WebJobs持续运行。

在此处输入图像描述

  • I have updated the Stack settings run time Version to .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.
  • In the second Console App, I haven't Configured the WebJobs and Storage Account .在第二个控制台应用程序中,我还没有配置WebJobs和 Storage Account
  • Updated the code and published again.更新了代码,再次发布。
  • Now I can see both the Jobs are in Running State.现在我可以看到两个作业都在运行 State。

在此处输入图像描述

在此处输入图像描述

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();
            }
        }
    }
}

Reference taken from MSDoc .参考资料取自MSDoc

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM