Using session.Advanced.Stream() with IIS and HttpCompression

716 views
Skip to first unread message

Barry Hagan

unread,
Apr 1, 2013, 8:28:28 PM4/1/13
to rav...@googlegroups.com
I'd like to start working with the streaming feature in 2.5, but it does not appear to work right now if you are hosted in IIS and have Raven/HttpCompression set to true (default).

I'm using build 2544 on IIS 7.5, and I get this error returned by the server when attempting to make a stream request:

[ZLibException: The stream state of the underlying compression routine is inconsistent.]
   System.IO.Compression.DeflaterZLib.Deflate(FlushCode flushCode) +8770476
   System.IO.Compression.DeflaterZLib.ReadDeflateOutput(Byte[] outputBuffer, FlushCode flushCode, Int32& bytesRead) +159
   System.IO.Compression.DeflaterZLib.System.IO.Compression.IDeflater.GetDeflateOutput(Byte[] outputBuffer) +64
   System.IO.Compression.DeflateStream.WriteDeflaterOutput(Boolean isAsync) +72
   System.IO.Compression.DeflateStream.Write(Byte[] array, Int32 offset, Int32 count) +79
   System.IO.Compression.GZipStream.Write(Byte[] array, Int32 offset, Int32 count) +33
   System.Web.HttpWriter.FilterIntegrated(Boolean finalFiltering, IIS7WorkerRequest wr) +546
   System.Web.HttpResponse.UpdateNativeResponse(Boolean sendHeaders) +1018
   System.Web.HttpResponse.Flush(Boolean finalFlush, Boolean async) +175
   System.Web.HttpWriter.WriteFromStream(Byte[] data, Int32 offset, Int32 size) +160
   System.IO.Compression.DeflateStream.PurgeBuffers(Boolean disposing) +164
   System.IO.Compression.DeflateStream.Dispose(Boolean disposing) +34
   System.IO.Stream.Close() +28
   System.IO.Compression.GZipStream.Dispose(Boolean disposing) +63
   System.IO.Stream.Close() +28
   System.Web.HttpWriter.FilterIntegrated(Boolean finalFiltering, IIS7WorkerRequest wr) +12509279
   System.Web.HttpResponse.FilterOutput() +121
   System.Web.CallFilterExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +119
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +165


If I set Raven/HttpCompression to false for IIS or run using Raven.Server, things work as expected.

Oren Eini (Ayende Rahien)

unread,
Apr 1, 2013, 8:32:43 PM4/1/13
to ravendb



--
You received this message because you are subscribed to the Google Groups "ravendb" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ravendb+u...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Barry Hagan

unread,
Apr 2, 2013, 12:32:42 AM4/2/13
to rav...@googlegroups.com
It looks like this is because the QueryStreams Responder turns off buffered output.  I'm not sure if you can apply the GZipStream filter and still make incremental writes to the output stream with IIS.  Turning off the compression made it work, as does commenting out the BufferOutput=false line, but that sort of defeats the whole intention of streaming.

There are also a couple of other issues in here:
1) No Content-Type header is set when using the JsonOutputWriter so it defaults to text/html
2) Headers are being added after writing to the output stream which cannot be done with BufferOutput=false.  This is happening with the Temp-Request-Time header, and I believe it could potentially happen with Raven-Force-Primary-Server-Check when using replication.

Oren Eini (Ayende Rahien)

unread,
Apr 2, 2013, 12:47:00 AM4/2/13
to ravendb
1 & 2 are handled.

But I am not sure why there would be a problem here with IIS and unbuffered output.
In HttpListener, we aren't doing buffering, and the Gzip doesn't require it

Can you check that you aren't using Deflate instead of Gzip for some reason for compression?

Barry Hagan

unread,
Apr 2, 2013, 5:27:43 PM4/2/13
to rav...@googlegroups.com
Same thing happens if I explicitly use Gzip or Deflate.  Turning IIS compression on/off has no effect, although if I set Raven/HttpCompression to false and then modify the appplicationHost.config for IIS so it compresses "application/json; charset=utf-8" responses, then streaming works fine  with compression done by IIS rather than the response filter.  That is my workaround for now.

I have not found a way to leave context.Response.BufferOutput = false and have the GZipStream/DeflateStream filter added to the response without getting the exception when hosted in IIS7.5 or IIS Express.

Oren Eini (Ayende Rahien)

unread,
Apr 2, 2013, 5:43:40 PM4/2/13
to ravendb
Reply all
Reply to author
Forward
0 new messages