ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
From: me@dmitry.it
To: ruby-core@ruby-lang.org
Subject: [ruby-core:90368] [Ruby trunk Bug#15356] Rack::Deflater on Rails responds with no data on Ruby 2.6.0
Date: Fri, 07 Dec 2018 11:49:28 +0000 (UTC)	[thread overview]
Message-ID: <redmine.journal-75478.20181207114926.0dd800694eba90d2@ruby-lang.org> (raw)
In-Reply-To: redmine.issue-15356.20181128192351@ruby-lang.org

Issue #15356 has been updated by dm1try (Dmitry Dedov).


normalperson (Eric Wong) wrote:
> OK, I'm pretty sure r66268 fixes it.  It's still my fault, not
>  because of non-blocking I/O, but because of a misguided zlib
>  optimization, so I'm still a moron :<

though this patch leads to described behavior, it looks like the actual problem can be solved by putting `Rack::Deflater` to the proper place in middleware stack:
```
config.middleware.insert_after ActionDispatch::Static, Rack::Deflater
```
as the position on the bottom of the stack anyway leads to the wrong behavior(ex. different ETag is calculated for the same body on each request because ETag middleware is called after Deflater and Deflater uses timestamps for packing)


----------------------------------------
Bug #15356: Rack::Deflater on Rails responds with no data on Ruby 2.6.0
https://bugs.ruby-lang.org/issues/15356#change-75478

* Author: zunda (zunda an)
* Status: Closed
* Priority: Normal
* Assignee: 
* Target version: 
* ruby -v: ruby 2.6.0dev (2018-11-28 trunk 66081) [x86_64-linux]
* Backport: 2.4: UNKNOWN, 2.5: UNKNOWN
----------------------------------------
I'd like to report that a Rails app with `Rack::Deflater` enabled responds with a zero-length body on Ruby 2.6.0, to a request with `Accept-encoding: gzip` request header. It seems to happen at least on `x86_64-linux` (Ubuntu 18.04.1; see below for procedure for a reproduction) as well as on `universal.x86_64-darwin17` (macOS High Sierra 10.13.6; tested about a half year ago). I suspect some kind of change in behavior of pipe or named pipe is causing this.

## 1: Prepare a Rails app, enable Rack::Deflater, and run the server

~~~
$ rbenv install 2.6.0-dev
$ mkdir ruby26-rails-deflater
$ cd ruby26-rails-deflater
$ echo 2.6.0-dev > .ruby-version
$ ruby --version
ruby 2.6.0dev (2018-11-28 trunk 66081) [x86_64-linux]
$ cat <<_END > Gemfile
source 'https://rubygems.org'
gem 'rails', '~> 5.2.1'
_END
$ bundle install --path=vendor/bundle
$ bundle exec rails new test-deflater
$ cd test-deflater
$ sed -ie '/config.load_defaults 5.2/a config.middleware.use Rack::Deflater' \
config/application.rb
$ bundle exec rails s
~~~

## 2: Send a request

From another terminal, run the curl command. The `0` in the last line represents the first chunked response body with zero-length. I expect to see the "Yay! You're on Rails!" response body.

~~~
$ curl -H 'Accept-encoding: gzip' -v http://localhost:3000 --raw
* Rebuilt URL to: http://localhost:3000/
*   Trying 127.0.0.1...
* TCP_NODELAY set
* Connected to localhost (127.0.0.1) port 3000 (#0)
> GET / HTTP/1.1
> Host: localhost:3000
> User-Agent: curl/7.58.0
> Accept: */*
> Accept-encoding: gzip
> 
< HTTP/1.1 200 OK
< X-Frame-Options: SAMEORIGIN
< X-XSS-Protection: 1; mode=block
< X-Content-Type-Options: nosniff
< X-Download-Options: noopen
< X-Permitted-Cross-Domain-Policies: none
< Referrer-Policy: strict-origin-when-cross-origin
< Content-Type: text/html; charset=utf-8
< Vary: Accept-Encoding
< Content-Encoding: gzip
< ETag: W/"cd54cb5f8d93b7800b9e76460c5fe915"
< Cache-Control: max-age=0, private, must-revalidate
< Content-Security-Policy: script-src 'unsafe-inline'; style-src 'unsafe-inline'
< X-Request-Id: e671eca8-f6ff-4599-b241-ea00fd864f56
< X-Runtime: 0.033015
< Transfer-Encoding: chunked
< 
0

* Connection #0 to host localhost left intact
~~~

Puma logs doesn't show anything out of ordinary:

~~~
Started GET "/" for 127.0.0.1 at 2018-11-28 09:09:44 -1000
Processing by Rails::WelcomeController#index as */*
  Rendering /home/zunda/.rbenv/versions/2.6.0-dev/lib/ruby/gems/2.6.0/gems/railties-5.2.1.1/lib/rails/templates/rails/welcome/index.html.erb
  Rendered /home/zunda/.rbenv/versions/2.6.0-dev/lib/ruby/gems/2.6.0/gems/railties-5.2.1.1/lib/rails/templates/rails/welcome/index.html.erb (5.1ms)
Completed 200 OK in 17ms (Views: 10.8ms | ActiveRecord: 0.0ms)
~~~

Puma responds as expected without compression:

~~~
$ curl -s http://localhost:3000 | tail -8
      <p class="version">
        <strong>Rails version:</strong> 5.2.1.1<br />
        <strong>Ruby version:</strong> 2.6.0 (x86_64-linux)
      </p>
    </section>
  </div>
</body>
</html>
~~~



-- 
https://bugs.ruby-lang.org/

  parent reply	other threads:[~2018-12-07 11:49 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <redmine.issue-15356.20181128192351@ruby-lang.org>
2018-11-28 19:23 ` [ruby-core:90133] [Ruby trunk Bug#15356] Rack::Deflater on Rails responds with no data on Ruby 2.6.0 zundan
2018-11-29  8:46 ` [ruby-core:90157] " zundan
2018-11-29 10:38   ` [ruby-core:90160] " Eric Wong
2018-11-29 18:40 ` [ruby-core:90171] " zundan
2018-11-29 19:16   ` [ruby-core:90173] " Eric Wong
2018-12-01 20:35     ` [ruby-core:90217] " Eric Wong
2018-12-07  1:07 ` [ruby-core:90346] " zundan
2018-12-07  7:13   ` [ruby-core:90358] " Eric Wong
2018-12-07 11:39 ` [ruby-core:90366] " me
2018-12-07 11:49 ` me [this message]
2018-12-07 13:29   ` [ruby-core:90369] " Eric Wong
2018-12-07 20:57 ` [ruby-core:90374] " zundan

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://www.ruby-lang.org/en/community/mailing-lists/

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

  git send-email \
    --in-reply-to=redmine.journal-75478.20181207114926.0dd800694eba90d2@ruby-lang.org \
    --to=ruby-core@ruby-lang.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).