Log before releasing streams and firing tokens (#7583)
Might fix: https://github.com/aspnet/AspNetCore-Internal/issues/1659 I think writes complete too fast so we don't observe when the message gets logged
This commit is contained in:
parent
25f1f59378
commit
6bafb7cb6f
|
|
@ -116,7 +116,7 @@ namespace Microsoft.AspNetCore.Server.IIS.Core
|
||||||
}
|
}
|
||||||
catch (ConnectionResetException ex)
|
catch (ConnectionResetException ex)
|
||||||
{
|
{
|
||||||
ConnectionReset();
|
AbortIO(clientDisconnect: true);
|
||||||
error = ex;
|
error = ex;
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
|
|
@ -171,7 +171,7 @@ namespace Microsoft.AspNetCore.Server.IIS.Core
|
||||||
// We want to swallow IO exception and allow app to finish writing
|
// We want to swallow IO exception and allow app to finish writing
|
||||||
catch (ConnectionResetException)
|
catch (ConnectionResetException)
|
||||||
{
|
{
|
||||||
ConnectionReset();
|
AbortIO(clientDisconnect: true);
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
|
|
@ -184,11 +184,16 @@ namespace Microsoft.AspNetCore.Server.IIS.Core
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool AbortIO()
|
internal void AbortIO(bool clientDisconnect)
|
||||||
{
|
{
|
||||||
if (Interlocked.CompareExchange(ref _requestAborted, 1, 0) != 0)
|
if (Interlocked.CompareExchange(ref _requestAborted, 1, 0) != 0)
|
||||||
{
|
{
|
||||||
return false;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (clientDisconnect)
|
||||||
|
{
|
||||||
|
Log.ConnectionDisconnect(_logger, ((IHttpConnectionFeature)this).ConnectionId);
|
||||||
}
|
}
|
||||||
|
|
||||||
_bodyOutput.Dispose();
|
_bodyOutput.Dispose();
|
||||||
|
|
@ -208,8 +213,6 @@ namespace Microsoft.AspNetCore.Server.IIS.Core
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Abort(Exception reason)
|
public void Abort(Exception reason)
|
||||||
|
|
@ -218,15 +221,7 @@ namespace Microsoft.AspNetCore.Server.IIS.Core
|
||||||
_streams.Abort(reason);
|
_streams.Abort(reason);
|
||||||
NativeMethods.HttpCloseConnection(_pInProcessHandler);
|
NativeMethods.HttpCloseConnection(_pInProcessHandler);
|
||||||
|
|
||||||
AbortIO();
|
AbortIO(clientDisconnect: false);
|
||||||
}
|
|
||||||
|
|
||||||
internal void ConnectionReset()
|
|
||||||
{
|
|
||||||
if (AbortIO())
|
|
||||||
{
|
|
||||||
Log.ConnectionDisconnect(_logger, ((IHttpConnectionFeature)this).ConnectionId);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -263,7 +263,7 @@ namespace Microsoft.AspNetCore.Server.IIS.Core
|
||||||
// don't leak the exception
|
// don't leak the exception
|
||||||
catch (ConnectionResetException)
|
catch (ConnectionResetException)
|
||||||
{
|
{
|
||||||
ConnectionReset();
|
AbortIO(clientDisconnect: true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -164,7 +164,7 @@ namespace Microsoft.AspNetCore.Server.IIS.Core
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
context = (IISHttpContext)GCHandle.FromIntPtr(pvManagedHttpContext).Target;
|
context = (IISHttpContext)GCHandle.FromIntPtr(pvManagedHttpContext).Target;
|
||||||
context.ConnectionReset();
|
context.AbortIO(clientDisconnect: true);
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -209,9 +209,9 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests
|
||||||
{
|
{
|
||||||
Assert.IsType<OperationCanceledException>(exception);
|
Assert.IsType<OperationCanceledException>(exception);
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception)
|
||||||
{
|
{
|
||||||
Logger.LogError(e, "Unexpected exception");
|
Logger.LogError(exception, "Unexpected exception type");
|
||||||
throw;
|
throw;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue