Initialize HttpConnectionManager before registering callbacks (#2878)
This commit is contained in:
parent
f91ba38907
commit
f42f4c56e6
|
|
@ -10,7 +10,6 @@ using System.IO;
|
||||||
using System.IO.Pipelines;
|
using System.IO.Pipelines;
|
||||||
using System.Net.WebSockets;
|
using System.Net.WebSockets;
|
||||||
using System.Security.Cryptography;
|
using System.Security.Cryptography;
|
||||||
using System.Threading;
|
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Microsoft.AspNetCore.Hosting;
|
using Microsoft.AspNetCore.Hosting;
|
||||||
using Microsoft.AspNetCore.Internal;
|
using Microsoft.AspNetCore.Internal;
|
||||||
|
|
@ -36,9 +35,11 @@ namespace Microsoft.AspNetCore.Http.Connections.Internal
|
||||||
{
|
{
|
||||||
_logger = loggerFactory.CreateLogger<HttpConnectionManager>();
|
_logger = loggerFactory.CreateLogger<HttpConnectionManager>();
|
||||||
_connectionLogger = loggerFactory.CreateLogger<HttpConnectionContext>();
|
_connectionLogger = loggerFactory.CreateLogger<HttpConnectionContext>();
|
||||||
|
_nextHeartbeat = new TimerAwaitable(_heartbeatTickRate, _heartbeatTickRate);
|
||||||
|
|
||||||
|
// Register these last as the callbacks could run immediately
|
||||||
appLifetime.ApplicationStarted.Register(() => Start());
|
appLifetime.ApplicationStarted.Register(() => Start());
|
||||||
appLifetime.ApplicationStopping.Register(() => CloseConnections());
|
appLifetime.ApplicationStopping.Register(() => CloseConnections());
|
||||||
_nextHeartbeat = new TimerAwaitable(_heartbeatTickRate, _heartbeatTickRate);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Start()
|
public void Start()
|
||||||
|
|
|
||||||
|
|
@ -314,6 +314,29 @@ namespace Microsoft.AspNetCore.Http.Connections.Tests
|
||||||
await tcs.Task.OrTimeout();
|
await tcs.Task.OrTimeout();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task ApplicationLifetimeCanStartBeforeHttpConnectionManagerInitialized()
|
||||||
|
{
|
||||||
|
var appLifetime = new TestApplicationLifetime();
|
||||||
|
appLifetime.Start();
|
||||||
|
|
||||||
|
var connectionManager = CreateConnectionManager(appLifetime);
|
||||||
|
var tcs = new TaskCompletionSource<object>();
|
||||||
|
|
||||||
|
var connection = connectionManager.CreateConnection(PipeOptions.Default, PipeOptions.Default);
|
||||||
|
|
||||||
|
connection.Application.Output.OnReaderCompleted((error, state) =>
|
||||||
|
{
|
||||||
|
tcs.TrySetResult(null);
|
||||||
|
},
|
||||||
|
null);
|
||||||
|
|
||||||
|
appLifetime.StopApplication();
|
||||||
|
|
||||||
|
// Connection should be disposed so this should complete immediately
|
||||||
|
await tcs.Task.OrTimeout();
|
||||||
|
}
|
||||||
|
|
||||||
private static HttpConnectionManager CreateConnectionManager(IApplicationLifetime lifetime = null)
|
private static HttpConnectionManager CreateConnectionManager(IApplicationLifetime lifetime = null)
|
||||||
{
|
{
|
||||||
lifetime = lifetime ?? new EmptyApplicationLifetime();
|
lifetime = lifetime ?? new EmptyApplicationLifetime();
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue