2017-06-02 6 views
3

Nous utilisons le noyau asp.net fonctionnant sous .net 4.5.1 en tant que service Windows. Kestrel est utilisé comme serveur web (la version de Kestrel est 1.1.2). Il a été configuré conformément à Host an ASP.NET Core app in a Windows Service. Nous utilisons également SignalR sur OWIN.Impossible d'arrêter le service Windows asp.net de base lorsque Kestrel reçoit des demandes

Le problème se produit lorsque deux événements se produisent simultanément: Windows Service s'arrête et certaines nouvelles demandes Web ont été reçues par Krestel. Si ces conditions sont remplies, le service Windows cesse de répondre et se bloque.

Windows n'a pas pu arrêter le service Topshelf.Host sur l'ordinateur local. Erreur 1061: Le service ne peut pas accepter les messages de contrôle pour le moment.

code Confuguration:

var port = Global.Settings.Port; 
var hostBuilder = new WebHostBuilder()     
       .UseKestrel()     
       .UseStartup<Startup>() 
       .UseUrls("http://+:" + port); 

if (runAsService) 
{      
     hostBuilder.UseContentRoot(directoryPath); 
     Directory.SetCurrentDirectory(directoryPath); 
} 
else 
{      
    hostBuilder.UseContentRoot(Directory.GetCurrentDirectory()); 
} 

var host = hostBuilder.Build(); 
if (runAsService) 
{     
    host.RunAsCustomService(); 
} 
else 
{      
     host.Run(); 
} 

public static class WebHostServiceExtensions 
{ 
    public static void RunAsCustomService(this IWebHost host) 
    { 
     var webHostService = new CustomWebHostService(host); 
     ServiceBase.Run(webHostService); 
    } 
} 
internal class CustomWebHostService : WebHostService 
{ 
    public CustomWebHostService(IWebHost host) : base(host) 
    { 
    } 

//... 
} 

investigation plus approfondie a révélé que exception non gérée est survenue lors de l'élimination _host dans WebHostService.cs.

protected sealed override void OnStop() 
{ 
    _stopRequestedByWindows = true; 
    OnStopping(); 
    _host?.Dispose(); 
    OnStopped(); 
} 

Comme décrit ci-dessous, il déclenche une exception "Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvException: Erreur -4082 ressource EBUSY occupé ou verrouillé"

La question est:

Existe-t-il un moyen d'éviter une telle erreur et d'empêcher le blocage du service Windows? Par exemple. arrêter Krestel avant _host disposition ou empêcher la nouvelle connexion entrante dans l'événement OnStopping.

Stacktrace:

Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvException: Erreur -4082 des ressources EBUSY occupé ou bloqué
dans Microsoft.AspNetCore.Server.Kestrel.Internal. Networking.Libuv.loop_close (UvLoopHandle poignée) dans Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvLoopHandle.ReleaseHandle() dans System.Runtime.InteropServices.SafeHandle.InternalDispose() dans System.Runtime.InteropServices. SafeHandle. Dispose (Boolean élimination)
dans System.Runtime.InteropServices.SafeHandle.Dispose() dans Microsoft.AspNetCore.Server.Kestrel.Internal.KestrelThread.ThreadStart (paramètre de l'objet )

dans Microsoft.AspNetCore.Server .Kestrel.Internal.KestrelThread.d__51.MoveNext() dans System.Threading.Tasks.Task.WaitAll (tâches [], Int32 millisecondsTimeout, CancellationToken cancellationToken) dans Microsoft.AspNetCore.Server.Kestrel.Internal.KestrelEngine. Dispose()
dans Microsoft.AspNetCore.Server.Kestrel.KestrelServer.Dispose() dans Microsoft.Extensions. DependencyInjection.ServiceProvider.Dispose()
dans Microsoft.AspNetCore.Hosting.Internal.WebHost.Dispose()

Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvException: Erreur -4082 EBUSY ressource occupé ou bloqué dans Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv.loop_close (UvLoopHandle poignée) dans Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvLoopHandle.ReleaseHandle() dans System.Runtime.InteropServices.SafeHandle.InternalDispose() dans System.Runtime.InteropServices.SafeHandle.Dispose (Boolean élimination)
dans System.Runtime.InteropServices.SafeHandle.Dispose() dans Microsoft.AspNetCore. Server.Kestrel.Internal.KestrelThread.ThreadStart (paramètre )

M icrosoft.AspNetCore.Server.Kestrel.Internal.KestrelThread.d__51.MoveNext()

+0

ressemble à un problème avec Kestrel. Essayez de soulever un problème dans [repo] (https://github.com/aspnet/KestrelHttpServer/issues) – Set

Répondre

0

Les exceptions EBUSY lancées à partir de KestrelServer.Dispose() will be fixed dans la version 2.0 de Kestrel. Je pense que la raison pour laquelle votre service est suspendu est parce que _host?.Dispose() lance qui empêche OnStopped(); d'être appelé à l'intérieur de la méthode OnStop(). En attendant, avaler l'exception pour s'assurer que OnStopped(); est toujours appelé devrait permettre l'arrêt du service. Assurez-vous de créer un nouveau WebHost si vous souhaitez redémarrer le serveur.