rack-devel archive mirror (unofficial) https://groups.google.com/group/rack-devel
 help / color / mirror / Atom feed
From: Aaron Patterson <tenderlove@ruby-lang.org>
To: Eric Wong <e@80x24.org>
Cc: rack-devel@googlegroups.com
Subject: Re: [PATCH] deflater: always finish zlib stream before closing
Date: Mon, 21 Sep 2015 14:50:34 -0700	[thread overview]
Message-ID: <20150921215034.GA90032@TC.local> (raw)
In-Reply-To: <20150921211615.GA8804@dcvr.yhbt.net>

[-- Attachment #1: Type: text/plain, Size: 3732 bytes --]

Applied, thanks!

On Mon, Sep 21, 2015 at 09:16:15PM +0000, Eric Wong wrote:
> This helps avoid Zlib::DataError when a client disconnects on
> the server while the server is writing the response.
> 
> This fixes the following backtraces on my server:
> 
>   data error (Zlib::DataError)
>   rack/deflater.rb:124:in `close'
>   rack/deflater.rb:124:in `ensure in each'
>   rack/deflater.rb:124:in `each'
>   rack/chunked.rb:23:in `each'
>   ...
> ---
>   If you prefer: git pull git://80x24.org/rack zlib-disco
> 
>   The following changes since commit c28f271d0c91f45e13bfa8f07bed445ef91f41de:
> 
>     Merge pull request #942 from keepcosmos/remove-fulltest-guide (2015-09-08 07:45:02 -0700)
> 
>   are available in the git repository at:
> 
>     git://80x24.org/rack zlib-disco
> 
>   for you to fetch changes up to f769efe714f5b8b417e0440ce05f8b4e4b504c57:
> 
>     deflater: always finish zlib stream before closing (2015-09-21 21:11:50 +0000)
> 
>   ----------------------------------------------------------------
>   Eric Wong (1):
>         deflater: always finish zlib stream before closing
> 
>  lib/rack/deflater.rb  |  3 ++-
>  test/spec_deflater.rb | 25 +++++++++++++++++++++++++
>  2 files changed, 27 insertions(+), 1 deletion(-)
> 
> diff --git a/lib/rack/deflater.rb b/lib/rack/deflater.rb
> index 19dc755..62a1124 100644
> --- a/lib/rack/deflater.rb
> +++ b/lib/rack/deflater.rb
> @@ -118,8 +118,9 @@ module Rack
>        def each
>          deflator = ::Zlib::Deflate.new(*DEFLATE_ARGS)
>          @body.each { |part| yield deflator.deflate(part, Zlib::SYNC_FLUSH) }
> -        yield deflator.finish
> +        yield fin = deflator.finish
>        ensure
> +        deflator.finish unless fin
>          deflator.close
>        end
>  
> diff --git a/test/spec_deflater.rb b/test/spec_deflater.rb
> index 2c7a428..ba7ec5d 100644
> --- a/test/spec_deflater.rb
> +++ b/test/spec_deflater.rb
> @@ -114,6 +114,31 @@ describe Rack::Deflater do
>      end
>    end
>  
> +  it 'does not raise when a client aborts reading' do
> +    app_body = Object.new
> +    class << app_body; def each; yield('foo'); yield('bar'); end; end
> +    opts = { 'skip_body_verify' => true }
> +    verify(200, app_body, 'deflate', opts) do |status, headers, body|
> +      headers.must_equal({
> +        'Content-Encoding' => 'deflate',
> +        'Vary' => 'Accept-Encoding',
> +        'Content-Type' => 'text/plain'
> +      })
> +
> +      buf = []
> +      inflater = Zlib::Inflate.new(-Zlib::MAX_WBITS)
> +      FakeDisconnect = Class.new(RuntimeError)
> +      assert_raises(FakeDisconnect, "not Zlib::DataError not raised") do
> +        body.each do |part|
> +          buf << inflater.inflate(part)
> +          raise FakeDisconnect
> +        end
> +      end
> +      assert_raises(Zlib::BufError) { inflater.finish }
> +      buf.must_equal(%w(foo))
> +    end
> +  end
> +
>    # TODO: This is really just a special case of the above...
>    it 'be able to deflate String bodies' do
>      verify(200, 'Hello world!', 'deflate') do |status, headers, body|
> -- 
> EW
> 
> -- 
> 
> --- 
> You received this message because you are subscribed to the Google Groups "Rack Development" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to rack-devel+unsubscribe@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

-- 
Aaron Patterson
http://tenderlovemaking.com/

-- 

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

[-- Attachment #2: Type: application/pgp-signature, Size: 455 bytes --]

      reply	other threads:[~2015-09-21 21:50 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-09-21 21:16 [PATCH] deflater: always finish zlib stream before closing Eric Wong
2015-09-21 21:50 ` Aaron Patterson [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://groups.google.com/group/rack-devel

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20150921215034.GA90032@TC.local \
    --to=rack-devel@googlegroups.com \
    --cc=e@80x24.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).