删除Service Fabric App后,进程仍保持运行 [英] Processes still keep running after Service Fabric App is removed
问题描述
我已经看到,当我删除服务结构应用程序时.应用程序内部服务的旧进程仍保持运行.
I have seen that when I remove a service fabric application. The old processes for the services inside the application still keep running.
应用程序中包含的服务属于类型
The services included in the Apps are of types
-
演员
无状态服务
ASP.NET Core
ASP.NET Core
当我重新部署应用程序并且ASP.NET Core服务针对"EADDRINUSE地址已在使用中"引发错误时,我注意到了这个问题.
I noticed the problem when I redeployed the application and the ASP.NET Core service threw an error for "EADDRINUSE address already in use"
是否有适当的方法来干净地删除应用程序,从而停止服务的所有内部进程?
Is there a proper way to cleanly remove the application which stops all the internal processes for the services?
在流程中是否可以捕获取消事件?
Is there any cancellation event which can be captured in the processes?
我正在使用以下类将其注册为无状态服务.
I am using the following class for Registering it as a Stateless service.
/// <summary>
/// A specialized stateless service for hosting ASP.NET Core web apps.
/// </summary>
internal sealed class WebHostingService : StatelessService, ICommunicationListener
{
private readonly string _endpointName;
private IWebHost _webHost;
public WebHostingService(StatelessServiceContext serviceContext, string endpointName)
: base(serviceContext)
{
_endpointName = endpointName;
}
#region StatelessService
protected override IEnumerable<ServiceInstanceListener> CreateServiceInstanceListeners()
{
return new[] { new ServiceInstanceListener(_ => this) };
}
#endregion StatelessService
#region ICommunicationListener
void ICommunicationListener.Abort()
{
_webHost?.Dispose();
}
Task ICommunicationListener.CloseAsync(CancellationToken cancellationToken)
{
_webHost?.Dispose();
return Task.FromResult(true);
}
Task<string> ICommunicationListener.OpenAsync(CancellationToken cancellationToken)
{
var endpoint = FabricRuntime.GetActivationContext().GetEndpoint(_endpointName);
string serverUrl = $"{endpoint.Protocol}://{FabricRuntime.GetNodeContext().IPAddressOrFQDN}:{endpoint.Port}";
_webHost = new WebHostBuilder().UseKestrel()
.UseContentRoot(Directory.GetCurrentDirectory())
.UseStartup<Startup>()
.UseUrls(serverUrl)
.Build();
_webHost.Start();
return Task.FromResult(serverUrl);
}
#endregion ICommunicationListener
}
并像这样注册它
ServiceRuntime.RegisterServiceAsync("WebApiType", context => new WebHostingService(context, "ServiceEndpoint")).GetAwaiter().GetResult();
Thread.Sleep(Timeout.Infinite);
推荐答案
我从空WebApi开始,这是从服务结构.NET核心WebApi模板中获得的.继续添加功能,直到我看到服务无法正常关闭.
I started out with empty WebApi, one you get from the service fabric .NET core WebApi templates. Continued to add features till I could see services not shutting down properly.
我发现我们正在使用Unity注入控制器.
I found out that we were injecting controllers with Unity.
由于我们不应该注入控制器,因此我进行了更新以删除该控制器,并且还通过Unity更新了其他注入,以支持内置的IServiceCollection注入.
As we should not be injecting controller, I updated to remove that and also updated other Injections via Unity in favor of the built in IServiceCollection injections.
这些更改之后,我在升级时没有看到端口已在使用中的错误.我确实看到旧进程仍在运行,但是没有使用任何CPU和内存(0.1M),然后在10-15分钟后消失了.
After these changes I do not see port already in use errors when I upgrade. I do see the old process still running though but not using any CPU and memory(0.1M) and then die out after 10-15mins.
这篇关于删除Service Fabric App后,进程仍保持运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!