TelemetryClient.Flu sh () занимает около 2 минут для запуска при выходе из приложения - PullRequest
0 голосов
/ 22 февраля 2020

У меня есть консольное приложение. NET Core 3.1, работающее в качестве размещенной службы. Когда приложение закрывается, оно зависает примерно на 2 минуты. При взломе я вижу, что он зависает на TelemetryClient.Flu sh (), в частности, внутри InMemoryChannel.Flu sh ().

Так что я смотрю результат в Fiddler и вижу приложение отправляет запрос на https://dc.services.visualstudio.com/v2/track, чтобы сообщить о телеметрии, но эта служба не отвечает. В конце концов, через 2 минуты ответ завершается с ошибкой 500 и в ответе через Интернет: «Подробная ошибка IIS 10.0 - 500.1013 - Внутренняя ошибка сервера».

Я не могу сказать, является ли это чем-то, что я делаю неправильно или нет. Поэтому я сократил приложение до минимума.

using System;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.ApplicationInsights;
using Microsoft.ApplicationInsights.Extensibility;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Options;

namespace DotNetCoreConsoleAppTest
{
    public class Program
    {
        public static async Task Main()
        {
            await Host.CreateDefaultBuilder()
                .ConfigureServices(services =>
                {
                    services
                        .Configure<TelemetryConfiguration>(options =>
                        {
                            options.InstrumentationKey = "<put your key here>";
                        })
                        .AddSingleton<TelemetryWriter>()
                        .AddHostedService<ProgramHost>();
                })
                .RunConsoleAsync()
                .ConfigureAwait(false);
        }
    }

    public class TelemetryWriter : IDisposable
    {
        private readonly TelemetryClient _telemetryClient;

        public TelemetryWriter(IOptions<TelemetryConfiguration> telemetryConfiguration)
        {
            _telemetryClient = new TelemetryClient(telemetryConfiguration.Value);
        }

        public void WriteEvent() => _telemetryClient.TrackEvent("test");

        public void Dispose() => _telemetryClient.Flush();
    }

    public class ProgramHost : IHostedService
    {
        private readonly TelemetryWriter _telemetryWriter;
        private readonly IHostApplicationLifetime _hostApplicationLifetime;

        public ProgramHost(
            TelemetryWriter telemetryWriter,
            IHostApplicationLifetime hostApplicationLifetime)
        {
            _telemetryWriter = telemetryWriter;
            _hostApplicationLifetime = hostApplicationLifetime;
        }

        public Task StartAsync(CancellationToken cancellationToken)
        {
            _telemetryWriter.WriteEvent();
            _hostApplicationLifetime.StopApplication();
            return Task.CompletedTask;
        }

        public Task StopAsync(CancellationToken cancellationToken) => Task.CompletedTask;
    }
}

Некоторая информация из веб-ответа:

<div class="content-container"> 
 <fieldset><h4>Detailed Error Information:</h4> 
  <div id="details-left"> 
   <table border="0" cellpadding="0" cellspacing="0"> 
    <tr class="alt"><th>Module</th><td>&nbsp;&nbsp;&nbsp;iisnode</td></tr> 
    <tr><th>Notification</th><td>&nbsp;&nbsp;&nbsp;ExecuteRequestHandler</td></tr> 
    <tr class="alt"><th>Handler</th><td>&nbsp;&nbsp;&nbsp;iisnode</td></tr> 
    <tr><th>Error Code</th><td>&nbsp;&nbsp;&nbsp;0x0000006d</td></tr> 

   </table> 
  </div> 
  <div id="details-right"> 
   <table border="0" cellpadding="0" cellspacing="0"> 
    <tr class="alt"><th>Requested URL</th><td>&nbsp;&nbsp;&nbsp;https://dc.services.visualstudio.com:443/InputServer.js</td></tr> 
    <tr><th>Physical Path</th><td>&nbsp;&nbsp;&nbsp;E:\sitesroot\0\InputServer.js</td></tr> 
    <tr class="alt"><th>Logon Method</th><td>&nbsp;&nbsp;&nbsp;Anonymous</td></tr> 
    <tr><th>Logon User</th><td>&nbsp;&nbsp;&nbsp;Anonymous</td></tr> 
    <tr class="alt"><th>Request Tracing Directory</th><td>&nbsp;&nbsp;&nbsp;C:\Resources\directory\f3eec886680f474eb56deb0e59f20036.Breeze.DiagnosticStore\FailedReqLogFiles\Web</td></tr> 
   </table> 
   <div class="clear"></div> 
  </div> 
 </fieldset> 
</div> 

Трассировка зависшего стека:

System.Private.CoreLib.dll!System.Threading.ManualResetEventSlim.Wait(int millisecondsTimeout, System.Threading.CancellationToken cancellationToken)    Unknown
System.Private.CoreLib.dll!System.Threading.Tasks.Task.SpinThenBlockingWait(int millisecondsTimeout, System.Threading.CancellationToken cancellationToken)  Unknown
System.Private.CoreLib.dll!System.Threading.Tasks.Task.InternalWaitCore(int millisecondsTimeout, System.Threading.CancellationToken cancellationToken)  Unknown
System.Private.CoreLib.dll!System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(System.Threading.Tasks.Task task)    Unknown
System.Private.CoreLib.dll!System.Runtime.CompilerServices.TaskAwaiter.GetResult()  Unknown
Microsoft.ApplicationInsights.dll!Microsoft.ApplicationInsights.Channel.InMemoryTransmitter.DequeueAndSend(System.TimeSpan timeout) Unknown
Microsoft.ApplicationInsights.dll!Microsoft.ApplicationInsights.Channel.InMemoryTransmitter.Flush(System.TimeSpan timeout)  Unknown
Microsoft.ApplicationInsights.dll!Microsoft.ApplicationInsights.Channel.InMemoryChannel.Flush(System.TimeSpan timeout)  Unknown
Microsoft.ApplicationInsights.dll!Microsoft.ApplicationInsights.Channel.InMemoryChannel.Flush() Unknown
Microsoft.ApplicationInsights.dll!Microsoft.ApplicationInsights.TelemetryClient.Flush() Unknown
DotNetCoreConsoleAppTest.dll!DotNetCoreConsoleAppTest.TelemetryWriter.Dispose() Line 43 C#
Microsoft.Extensions.DependencyInjection.dll!Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceProviderEngineScope.DisposeAsync()   Unknown
Microsoft.Extensions.Hosting.dll!Microsoft.Extensions.Hosting.Internal.Host.DisposeAsync()  Unknown
Microsoft.Extensions.Hosting.Abstractions.dll!Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.RunAsync(Microsoft.Extensions.Hosting.IHost host, System.Threading.CancellationToken token)    Unknown
Microsoft.Extensions.Hosting.dll!Microsoft.Extensions.Hosting.HostingHostBuilderExtensions.RunConsoleAsync(Microsoft.Extensions.Hosting.IHostBuilder hostBuilder, System.Threading.CancellationToken cancellationToken) Unknown
DotNetCoreConsoleAppTest.dll!DotNetCoreConsoleAppTest.Program.Main() Line 16    C#
DotNetCoreConsoleAppTest.dll!DotNetCoreConsoleAppTest.Program.<Main>()  Unknown

Несмотря на все это, события появляются в журналах Application Insights. Единственная проблема - зависание моего хост-приложения. Это проблема с тем, как я пытаюсь гриппа sh ()? Или это проблема службы Application Insights?

1 Ответ

0 голосов
/ 23 февраля 2020

ZakiMa ответил на мой вопрос - у App Insights был сбой.

...