Server-Sent-Events останавливается в среднем потоке при запуске в Azure и .Net Core - PullRequest
0 голосов
/ 30 июня 2019

У меня есть две разные страницы, обслуживающие длительно отправленные события HTTP-сервера. Когда я работаю в своей среде разработки, они оба работают нормально. Но когда я публикую его в Azure ... тогда, когда я запускаю один, он гудит, пока я не запускаю другой, а затем первый останавливается в середине потока ... например:

data:{"Symbol":"AAWW","Last":["2019-06-30T02:03:16",44.63]}
data:{"Symbol":"ACWF","Last":["2019-06-30T02:03:16",29.29]}
data:{"Symbol":"AAME","Last":["2019-06-30T02:03:16",2.46]}
data:{"Symbol":"ABC","Last":["2019-06-30T02:03:16",85.28]}
data:{"Symbol":"ABEV","Last":["2019-0

Я пытался отлавливать ошибки, просматривать журналы (см. Ниже) ... и я понятия не имею, почему это происходит или даже почему это происходит. Любая помощь?

**** Обновление ****

Когда я делаю второй вызов так же просто, как это ... происходит то же самое!

    [HttpGet]
    [Route("EquityCurve_Daily_WithRealtimeUpdates")]
    public void EquityCurve_Daily_WithRealtimeUpdates(CancellationToken cancellationToken, long tradingAccountId, string securityKey)
    {
        var xx = new ManualResetEventSlim(false);
        xx.Wait(cancellationToken);
    }

Код контроллера для одного из них: (они оба довольно похожи):

    [HttpGet]
    [Route("Prices_LastCloseAndRealtime")]
    public void Prices_LastCloseAndRealtime(CancellationToken cancellationToken, string symbols, string securityKey)
    {
        try
        {
            _log.Debug("Prices_LastCloseAndRealtime Starting");

            TimeBasedSecurityKey.Validate(securityKey);

            Response.ContentType = "text/event-stream";

            var symbolList = new SymbolList(symbols);

            _priceService_Realtime.GetPricesData_LastCloseAndRealtime(cancellationToken, symbolList,
                (symbol, timeValuePair) => // realtimeUpdates
                {
                    var message = "data:{\"Symbol\":\"" + symbol + "\",\"Last\":" + timeValuePair.Serialize(TimeSeriesSerializationType.Normal) + "}\n\n";
                    HttpResponseWritingExtensions.WriteAsync(this.Response, message).Wait();
                    Response.Body.FlushAsync().Wait();
                }
            );
            _log.Debug("Prices_LastCloseAndRealtime Finished");
        }
        catch (Exception ex)
        {
            _log.Error(ex);
            HttpResponseWritingExtensions.WriteAsync(this.Response, ex.Message).Wait();
            Response.Body.FlushAsync().Wait();
        }
    }

GetPricesData_LastCloseAndRealtime в основном делает это:

            PriceServer.Instance.Connect(subscriber, (priceData) =>
            {
                var resultSeries = new PriceSeries();
                resultSeries.Add((DateTime)priceData.Time, priceData.Last);
                onPriceSeries(priceData.Symbol, resultSeries);
            });

            foreach (var symbol in symbolList)
                PriceServer.Instance.Subscribe(subscriber, symbol);

            var _auto = new ManualResetEventSlim(false);
            _auto.Wait(cancellationToken);

            _log.Debug("This doesn't get hit when the second page is loaded");

Журналы из Azure:

2019-06-30 03:08:38.970 +00:00 [Information] Microsoft.AspNetCore.Hosting.Internal.WebHost: Request starting HTTP/1.1 GET https://mydomain-qa.azurewebsites.net/api/ChartData/Prices_LastCloseAndRealtime?symbols=4Q%20Rotate,FANG,AADR,AAWW,ACIM,ACIW,ACSG,ACWF,AAME,ABB,ABC,ABEV,ABM,ABUS
2019-06-30 03:08:38.971 +00:00 [Information] Microsoft.AspNetCore.Routing.EndpointMiddleware: Executing endpoint 'mydomain.Controllers.ChartDataController.Prices_LastCloseAndRealtime (mydomain)'
2019-06-30 03:08:38.972 +00:00 [Information] Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker: Route matched with {action = "Prices_LastCloseAndRealtime", controller = "ChartData"}. Executing controller action with signature Void Prices_LastCloseAndRealtime(System.Threading.CancellationToken, System.String, System.String) on controller mydomain.Controllers.ChartDataController(mydomain).
2019-06-30 03:08:38.978 +00:00 [Information] Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker: Executing action method mydomain.Controllers.ChartDataController.Prices_LastCloseAndRealtime(mydomain) - Validation state: Valid
2019-06-30 03:08:38.978 +00:00 [Information] mydomain.Controllers.ChartDataController: Prices_LastCloseAndRealtime Starting

*** The above lines are from the first request ***

2019-06-30 03:08:51.441 +00:00 [Information] Microsoft.AspNetCore.Hosting.Internal.WebHost: Request starting HTTP/1.1 GET https://mydomain-qa.azurewebsites.net/api/ChartData/EquityCurve_Daily_WithRealtimeUpdates?tradingAccountId=1
2019-06-30 03:08:51.441 +00:00 [Information] Microsoft.AspNetCore.Routing.EndpointMiddleware: Executing endpoint 'mydomain.Controllers.ChartDataController.EquityCurve_Daily_WithRealtimeUpdates (mydomain)'
2019-06-30 03:08:51.441 +00:00 [Information] Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker: Route matched with {action = "EquityCurve_Daily_WithRealtimeUpdates", controller = "ChartData"}. Executing controller action with signature Void EquityCurve_Daily_WithRealtimeUpdates(System.Threading.CancellationToken, Int64, System.String) on controller mydomain.Controllers.ChartDataController(mydomain).
2019-06-30 03:08:51.442 +00:00 [Information] Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker: Executing action method mydomain.Controllers.ChartDataController.EquityCurve_Daily_WithRealtimeUpdates(mydomain) - Validation state: Valid
2019-06-30 03:08:51.442 +00:00 [Information] mydomain.Controllers.ChartDataController: EquityCurve_Daily_WithRealtimeUpdates Starting
2019-06-30 03:08:51.448 +00:00 [Information] Microsoft.EntityFrameworkCore.Infrastructure: Entity Framework Core 2.2.4-servicing-10062 initialized 'ApplicationDbContext' using provider 'Microsoft.EntityFrameworkCore.SqlServer' with options: None
2019-06-30 03:08:51.466 +00:00 [Information] Microsoft.EntityFrameworkCore.Database.Command: Executed DbCommand(15ms) [Parameters=[@__get_Item_0='?' (DbType = Int64)], CommandType='Text', CommandTimeout='30']SELECT TOP(1) [e].[TradingAccountId], [e].[AccountNumber], [e].[AccountTitle], [e].[BrokerId], [e].[CreatedBy], [e].[CreatedDate], [e].[EquityCurveId], [e].[FirstBrokerInfoDate], [e].[FirstFundedDate], [e].[InitialAccountValue], [e].[MostRecent_BODDailyValuesId], [e].[StartDate], [e].[UpdatedBy], [e].[UpdatedDate], [e].[UserId] FROM[TradingAccount] AS[e]WHERE[e].[TradingAccountId] = @__get_Item_0
2019-06-30 03:08:51.469 +00:00 [Information] Microsoft.EntityFrameworkCore.Database.Command: Executed DbCommand(1ms) [Parameters=[@__tradingAccountId_0='?' (DbType = Int64)], CommandType='Text', CommandTimeout='30']SELECT[p].[PositionId], [p].[CreatedBy], [p].[CreatedDate], [p].[DesiredQuantity], [p].[Entry_Commission], [p].[Entry_OrderId], [p].[Entry_Price], [p].[Entry_Time], [p].[Exit_Commission], [p].[Exit_OrderId], [p].[Exit_Price], [p].[Exit_Time], [p].[Quantity], [p].[SmartCardId], [p].[Symbol], [p].[TradingAccountId], [p].[UpdatedBy], [p].[UpdatedDate] FROM[Position] AS[p]WHERE[p].[TradingAccountId] = @__tradingAccountId_0
2019-06-30 03:08:51.485 +00:00 [Information] Microsoft.EntityFrameworkCore.Infrastructure: Entity Framework Core 2.2.4-servicing-10062 initialized 'PriceDbContext' using provider 'Microsoft.EntityFrameworkCore.SqlServer' with options: MigrationsAssembly=mydomain
2019-06-30 03:08:51.815 +00:00 [Information] Microsoft.EntityFrameworkCore.Database.Command: Executed DbCommand(220ms) [Parameters=[@__symbol_0='?' (Size = 40)], CommandType='Text', CommandTimeout='30']SELECT[db].[TradeDate], [db].[Close] FROM[DailyBar] AS[db]WHERE[db].[Symbol] = @__symbol_0ORDER BY[db].[TradeDate]

*** The above lines are from the second request (first request just stopped) ***

2019-06-30T03:08:50 PID[5928] Information 06-30 03:08:50 Critical: StopProfiler triggered.
2019-06-30T03:08:50 PID[5928] Information 06-30 03:08:50 Information: Stopping circular monitor and collecting etl snapshot.
...