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

ResponseCompression async APIs write synchronously #247

Closed
Tratcher opened this issue Jun 27, 2017 · 10 comments
Closed

ResponseCompression async APIs write synchronously #247

Tratcher opened this issue Jun 27, 2017 · 10 comments

Comments

@Tratcher
Copy link
Member

This is relevant because the servers are planning to disable sync IO: aspnet/HttpSysServer#366

net461

Server stack trace:
   at Microsoft.AspNetCore.Server.HttpSys.ResponseBody.Write(Byte[] buffer, Int32 offset, Int32 count)
   at Microsoft.AspNetCore.Server.HttpSys.ResponseStream.Write(Byte[] buffer, Int32 offset, Int32 count)
   at System.IO.Compression.DeflateStream.DoMaintenance(Byte[] array, Int32 offset, Int32 count)
   at System.IO.Compression.DeflateStream.InternalWrite(Byte[] array, Int32 offset, Int32 count, Boolean isAsync)
   at System.Runtime.Remoting.Messaging.StackBuilderSink._PrivateProcessMessage(IntPtr md, Object[] args, Object server, Object[]& outArgs)
   at System.Runtime.Remoting.Messaging.StackBuilderSink.AsyncProcessMessage(IMessage msg, IMessageSink replySink)

Exception rethrown at [0]:
   at System.IO.Compression.DeflateStream.EndWrite(IAsyncResult asyncResult)
   at System.IO.Compression.GZipStream.EndWrite(IAsyncResult asyncResult)
   at System.IO.Stream.<>c.<BeginEndWriteAsync>b__53_1(Stream stream, IAsyncResult asyncResult)
   at System.Threading.Tasks.TaskFactory`1.FromAsyncTrimPromise`1.Complete(TInstance thisRef, Func`3 endMethod, IAsyncResult asyncResult, Boolean requiresSynchronization)
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.GetResult()
   at Microsoft.AspNetCore.ResponseCompression.BodyWrapperStream.<WriteAsync>d__32.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.GetResult()
   at ResponseCompressionSample.Startup.<>c.<<Configure>b__1_4>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.AspNetCore.Builder.Extensions.MapMiddleware.<Invoke>d__3.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.AspNetCore.Builder.Extensions.MapMiddleware.<Invoke>d__3.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.GetResult()
   at Microsoft.AspNetCore.ResponseCompression.ResponseCompressionMiddleware.<Invoke>d__3.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.AspNetCore.Hosting.Internal.RequestServicesContainerMiddleware.<Invoke>d__3.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.ConfiguredTaskAwaitable.ConfiguredTaskAwaiter.GetResult()
   at Microsoft.AspNetCore.Server.HttpSys.MessagePump.<ProcessRequestAsync>d__20.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at Microsoft.AspNetCore.Server.HttpSys.MessagePump.<ProcessRequestAsync>d__20.MoveNext()

netcoreapp2.0

System.InvalidOperationException: Syncronous IO APIs are disabled, see AllowSynchronousIO.
   at Microsoft.AspNetCore.Server.HttpSys.ResponseBody.Write(Byte[] buffer, Int32 offset, Int32 count)
   at Microsoft.AspNetCore.Server.HttpSys.ResponseStream.Write(Byte[] buffer, Int32 offset, Int32 count)
   at System.IO.Compression.DeflateStream.PurgeBuffers(Boolean disposing)
   at System.IO.Compression.DeflateStream.Dispose(Boolean disposing)
   at System.IO.Stream.Close()
   at System.IO.Compression.GZipStream.Dispose(Boolean disposing)
   at System.IO.Stream.Close()
   at Microsoft.AspNetCore.ResponseCompression.BodyWrapperStream.Dispose(Boolean disposing) in C:\git\Universe\BasicMiddleware\src\Microsoft.AspNetCore.ResponseCompression\BodyWrapperStream.cs:line 46
   at System.IO.Stream.Close()
   at Microsoft.AspNetCore.ResponseCompression.ResponseCompressionMiddleware.<Invoke>d__3.MoveNext() in C:\git\Universe\BasicMiddleware\src\Microsoft.AspNetCore.ResponseCompression\ResponseCompressionMiddleware.cs:line 74
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.AspNetCore.Hosting.Internal.RequestServicesContainerMiddleware.<Invoke>d__3.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.AspNetCore.Server.HttpSys.MessagePump.<ProcessRequestAsync>d__20.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at Microsoft.AspNetCore.Server.HttpSys.MessagePump.<ProcessRequestAsync>d__20.MoveNext()
@halter73
Copy link
Member

I think we should open an issue in https://github.com/dotnet/corefx for DeflateStream. @Tratcher Did you verify that DeflateStream.FlushAsync() was being called by ResponseCompression prior to DeflateStream.Dispose()?

@Tratcher
Copy link
Member Author

@halter73
Copy link
Member

We should check tomorrow see if that fixes this issue on .NET Core. It's not unreasonable for DeflateStream.Dispose() to call InnerStream.Write() if there's still unflushed output.

@Tratcher
Copy link
Member Author

No, I had tried it, it was still calling Flush.

@muratg
Copy link
Contributor

muratg commented Feb 17, 2018

Bringing back to triage

@Zoxive
Copy link

Zoxive commented May 10, 2018

This is still missing in 2.1.0-rc1-final. Will this be done in RC2?

@Tratcher
Copy link
Member Author

No this isn't getting fixed for 2.1. We need to get some work done on the underlying compression streams to enable it. The worst cases I saw when I checked last were Flush and Dispose.

@muratg
Copy link
Contributor

muratg commented Oct 16, 2018

cc @davidfowl Something you may want to call out in your amazing new 'diagnosability' doc :)

@muratg muratg added this to the 3.0.0 milestone Oct 16, 2018
@muratg
Copy link
Contributor

muratg commented Oct 16, 2018

@Tratcher Tratcher added enhancement 1 - Ready and removed Investigate Investigation item task labels Nov 13, 2018
@Tratcher
Copy link
Member Author

This is now unblocked by dotnet/corefx#33415, pending picking up a new build.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants