Skip to content
This repository was archived by the owner on Dec 18, 2018. It is now read-only.

Commit

Permalink
PR feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
halter73 committed Apr 18, 2017
1 parent 2dc7295 commit 0155a10
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure;
using Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines;
using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions;
using Microsoft.Extensions.Internal;
using Microsoft.Extensions.Logging;

namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal
Expand All @@ -22,15 +21,15 @@ public class FrameConnection : IConnectionContext, ITimeoutControl
private readonly FrameConnectionContext _context;
private readonly Frame _frame;
private readonly List<IConnectionAdapter> _connectionAdapters;
private readonly TaskCompletionSource<object> _frameStartedTcs = new TaskCompletionSource<object>();
private readonly TaskCompletionSource<bool> _frameStartedTcs = new TaskCompletionSource<bool>();

private long _lastTimestamp;
private long _timeoutTimestamp = long.MaxValue;
private TimeoutAction _timeoutAction;

private AdaptedPipeline _adaptedPipeline;
private Stream _filteredStream;
private Task _adaptedPipelineTask = TaskCache.CompletedTask;
private Task _adaptedPipelineTask;

public FrameConnection(FrameConnectionContext context)
{
Expand Down Expand Up @@ -101,9 +100,11 @@ public async void OnConnectionClosed()

public async Task StopAsync()
{
await _frameStartedTcs.Task;
await _frame.StopAsync();
await _adaptedPipelineTask;
if (await _frameStartedTcs.Task)
{
await _frame.StopAsync();
await (_adaptedPipelineTask ?? Task.CompletedTask);
}
}

public void Abort(Exception ex)
Expand Down Expand Up @@ -158,7 +159,7 @@ private async Task ApplyConnectionAdaptersAsync()
catch (Exception ex)
{
Log.LogError(0, ex, $"Uncaught exception from the {nameof(IConnectionAdapter.OnConnectionAsync)} method of an {nameof(IConnectionAdapter)}.");
_frameStartedTcs.SetResult(null);
_frameStartedTcs.SetResult(false);
CloseRawPipes();
}
}
Expand Down Expand Up @@ -191,7 +192,7 @@ private void StartFrame()
{
_lastTimestamp = _context.ServiceContext.SystemClock.UtcNow.Ticks;
_frame.Start();
_frameStartedTcs.SetResult(null);
_frameStartedTcs.SetResult(true);
}

public void Tick(DateTimeOffset now)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@ public Task StopAsync()
Input.CancelPendingRead();

Debug.Assert(_requestProcessingTask != null);
return _requestProcessingTask;
return _requestProcessingTask ?? Task.CompletedTask;
}

private void CancelRequestAbortedToken()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure
{
public class FrameConnectionManager
{
// Internal for testing
internal readonly ConcurrentDictionary<long, FrameConnectionReference> _connectionReferences = new ConcurrentDictionary<long, FrameConnectionReference>();
private readonly ConcurrentDictionary<long, FrameConnectionReference> _connectionReferences = new ConcurrentDictionary<long, FrameConnectionReference>();
private readonly IKestrelTrace _trace;

public FrameConnectionManager(IKestrelTrace trace)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -239,9 +239,6 @@ private void ThreadStart(object parameter)
}
}

// This is used to access a 64-bit timestamp (this.Now) using a potentially 32-bit IntPtr.
var thisHandle = GCHandle.Alloc(this, GCHandleType.Weak);

try
{
_loop.Run();
Expand Down Expand Up @@ -271,7 +268,6 @@ private void ThreadStart(object parameter)
{
PipeFactory.Dispose();
WriteReqPool.Dispose();
thisHandle.Free();
_threadTcs.SetResult(null);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -446,12 +446,12 @@ public void RequestProcessingAsyncEnablesKeepAliveTimeout()
var connectionControl = new Mock<ITimeoutControl>();
_frame.TimeoutControl = connectionControl.Object;

var requestProcessingTask = _frame.RequestProcessingAsync();
_frame.Start();

var expectedKeepAliveTimeout = _serviceContext.ServerOptions.Limits.KeepAliveTimeout.Ticks;
connectionControl.Verify(cc => cc.SetTimeout(expectedKeepAliveTimeout, TimeoutAction.CloseConnection));

_frame.StopAsync();
var requestProcessingTask = _frame.StopAsync();
_input.Writer.Complete();

requestProcessingTask.Wait();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using System;
using System.Diagnostics;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Testing;
using Microsoft.AspNetCore.Testing.xunit;
using Microsoft.Extensions.Logging;
using Moq;
using Xunit;
Expand All @@ -17,7 +19,8 @@ public class FrameConnectionManagerTests
{
private const int _applicationNeverCompletedId = 23;

[Fact]
[ConditionalFact]
[NoDebuggerCondition]
public async Task CriticalErrorLoggedIfApplicationDoesntComplete()
{
////////////////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -89,5 +92,11 @@ await connection.Send("GET / HTTP/1.1",
Assert.True(logWaitAttempts < 10);
}
}

private class NoDebuggerConditionAttribute : Attribute, ITestCondition
{
public bool IsMet => !Debugger.IsAttached;
public string SkipReason => "A debugger is attached.";
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ public async Task LargeUpload(long? maxRequestBufferSize, bool connectionAdapter

using (var reader = new StreamReader(stream, Encoding.ASCII))
{
var response = await reader.ReadToEndAsync();
var response = reader.ReadToEnd();
Assert.Contains($"bytesRead: {data.Length}", response);
}
}
Expand Down

0 comments on commit 0155a10

Please sign in to comment.