Set IsBackground property to true on libuv Threads for non-debug builds

- If libuv doesn't shutdown as expected, the process will still stop. Thanks @benaadams!
- Address other minor PR feedback.
This commit is contained in:
Stephen Halter 2016-02-17 16:33:34 -08:00
parent 04736e1d09
commit bc56d11d8c
5 changed files with 13 additions and 11 deletions

View File

@ -23,7 +23,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http
{
if (_connectionStopTasks != null)
{
throw new InvalidOperationException(nameof(WalkConnectionsAndClose) + " cannot be called twice.");
throw new InvalidOperationException($"{nameof(WalkConnectionsAndClose)} cannot be called twice.");
}
_connectionStopTasks = new List<Task>();
@ -44,7 +44,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http
{
if (_connectionStopTasks == null)
{
throw new InvalidOperationException(nameof(WalkConnectionsAndClose) + " must be called first.");
throw new InvalidOperationException($"{nameof(WalkConnectionsAndClose)} must be called first.");
}
return Task.WhenAll(_connectionStopTasks);

View File

@ -189,12 +189,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Http
protected FrameRequestHeaders FrameRequestHeaders => _frameHeaders.RequestHeaders;
public Frame InitializeHeaders()
public void InitializeHeaders()
{
_frameHeaders = HttpComponentFactory.CreateHeaders(DateHeaderValueManager);
RequestHeaders = _frameHeaders.RequestHeaders;
ResponseHeaders = _frameHeaders.ResponseHeaders;
return this;
}

View File

@ -79,6 +79,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel
public void Stop(TimeSpan timeout)
{
#if !DEBUG
// Mark the thread as being as unimportant to keeping the process alive.
// Don't do this for debug builds, so we know if the thread isn't terminating.
_thread.IsBackground = true;
#endif
if (!_initCompleted)
{
return;

View File

@ -26,8 +26,8 @@ namespace Microsoft.AspNetCore.Server.KestrelTests
ServerInformation = serverInformation,
HttpComponentFactory = new HttpComponentFactory(serverInformation)
};
var frame = new Frame<object>(application: null, context: connectionContext)
.InitializeHeaders();
var frame = new Frame<object>(application: null, context: connectionContext);
frame.InitializeHeaders();
IDictionary<string, StringValues> headers = frame.ResponseHeaders;
@ -60,8 +60,8 @@ namespace Microsoft.AspNetCore.Server.KestrelTests
ServerInformation = serverInformation,
HttpComponentFactory = new HttpComponentFactory(serverInformation)
};
var frame = new Frame<object>(application: null, context: connectionContext)
.InitializeHeaders();
var frame = new Frame<object>(application: null, context: connectionContext);
frame.InitializeHeaders();
Assert.True(frame.ResponseHeaders.Count > 0);

View File

@ -3,10 +3,7 @@
using System;
using System.Threading;
using Microsoft.AspNetCore.Server.Kestrel;
using Microsoft.AspNetCore.Server.Kestrel.Http;
using Microsoft.AspNetCore.Server.Kestrel.Infrastructure;
using Microsoft.AspNetCore.Server.Kestrel.Networking;
namespace Microsoft.AspNetCore.Server.KestrelTests.TestHelpers
{