Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rails send_data sending 0 bytes after update to 5.0.26 #1763

Closed
fernandoluizao opened this issue Mar 3, 2016 · 23 comments

Comments

Projects
None yet
5 participants
@fernandoluizao
Copy link

commented Mar 3, 2016

Hi,

I have the following code:

  def index
     @items = Item.all
     respond_to do |format|
      format.csv do
        csv = CSV.generate({:col_sep => ';'}) do |csv|
          csv << ["Id", "Name"]

          @items.each do |item|
            csv << [
              item.id,
              item.name
            ]
          end
        end
        send_data csv.encode("UTF-16LE"), :filename => 'items.csv'
      end
    end
  end

This code was running nice on Passenger 5.0.25 with Apache, CSV is returned correctly.

But after upgrade to 5.0.26, my app is returning a 0 byte file.

I think it may be related to 9996880 but I'm not familiar with passenger sources. I'm doing something wrong?

Thanks!

@FooBarWidget FooBarWidget added this to the 5.0.27 milestone Mar 3, 2016

@FooBarWidget

This comment has been minimized.

Copy link
Member

commented Mar 3, 2016

Investigating this now.

@FooBarWidget

This comment has been minimized.

Copy link
Member

commented Mar 3, 2016

I can't reproduce this issue. Can you tell me the raw HTTP response on 5.0.25 and 5.0.26?

@fernandoluizao

This comment has been minimized.

Copy link
Author

commented Mar 3, 2016

No differences between the response of the two versions.

One thing I forgot to mention is that I'm using the deb packages from your ppa.

I can't reproduce this issue using rubygem.

Any idea?

@FooBarWidget

This comment has been minimized.

Copy link
Member

commented Mar 3, 2016

No differences between the response of the two versions.

I don't understand. Didn't you say that 5.0.26 yields a zero byte response while 5.0.25 yields a correct response?

@fernandoluizao

This comment has been minimized.

Copy link
Author

commented Mar 4, 2016

Sorry about that, here goes the response headers:

5.0.25

HTTP/1.1 200 OK
Date: Fri, 04 Mar 2016 10:26:06 GMT
Server: Apache/2.4.7 (Ubuntu)
Cache-Control: private
X-XSS-Protection: 1; mode=block
X-Request-Id: b2acf7c4-db70-446f-a552-575cce106cb4
Content-Disposition: attachment; filename="planos_corte.csv"
Content-Transfer-Encoding: binary
X-Frame-Options: SAMEORIGIN
X-Runtime: 0.148563
X-Content-Type-Options: nosniff
X-Powered-By: Phusion Passenger 5.0.25
Set-Cookie: _mes-slitter_session=OWwvb3N3NkVuRXBEc1V5VFp1a1VlTWU1Slh2NkRNeTA4OXplbUw5ai9UMlpaUXpPSTJ4cXMxb3RmMzhKaG1TbjVYOVFRY3pkdXN6Z2pKZWgwN256b3QwL1YvVllPeHhzbmR2QnBqbW1Bd3cxRVhBU0F4MDNMVEIwNWI3VncrWTRMMjRudDZlQVl0STdHYVpLQzk3S2RNT1ZMSmh0R0FwWEkvQzdRVWs5SENTVzJWbDBsSFVnQWRabkdzN3RCT2lZMGt2UktrcHZmaUs5MFQxQlE5bGNnWk91YjJzdWFjcyt0dGtJMzBGNjZNc3luZG14dU9ZTnJLa0pzZDV3QTNPZy0tazZnUk5XQVAxREx6Ykd2WitscGlQZz09--3270bedf6efd2f1ebc0768290f2f2e35c7c56911; path=/; HttpOnly
ETag: W/"de7f487c0fe25beed308f32a5cb65471"
Status: 200 OK
Keep-Alive: timeout=5, max=98
Connection: Keep-Alive
Transfer-Encoding: chunked
Content-Type: text/csv

5.0.26

Cache-Control:private
Connection:Keep-Alive
Content-Disposition:attachment; filename="planos_corte.csv"
Content-Length:0
Content-Transfer-Encoding:binary
Content-Type:text/csv
Date:Fri, 04 Mar 2016 10:29:18 GMT
ETag:W/"de7f487c0fe25beed308f32a5cb65471"
Keep-Alive:timeout=5, max=100
Server:Apache/2.4.7 (Ubuntu)
Set-Cookie:_mes-slitter_session=dWFSZi9GWndNa0ZYTGVIRXVBcGhLSVAzTEl6aVRBSHFNQmpQUkp5cElrTFUrajhlbDRvMlNiOUs2UXByMDU0Vm5nTnZPT0grdGhNc1dHU1dRV1pMOGJ2WlY4WVRNS3lSNktBTlhwdjM5b1NaYUlFM3FyVi9sd25PVDdBMW9BVy9SUlVRN2ZiazlxRkZiNHB1Vjh1YlZ0Ykl2NlRmdVR2ZzFmRWhHcTcxTEMyenJEaVE1OUg5Wnd0ODltMU9MMXo4NUZzdzVwYUVKSDFQV2lmS0U4UGZ5NUluNEtGMXJEVUozd2RvZ21rcExFOFZWWmNqNmZrb0JTK29tcXBsS0w5Qy0tbmE2V0xqTENUTFRCTWo0bURVT1h6dz09--5a015a92cc3e431f22d6cd629076d51b16ab976d; path=/; HttpOnly
Status:200 OK
X-Content-Type-Options:nosniff
X-Frame-Options:SAMEORIGIN
X-Powered-By:Phusion Passenger 5.0.26
X-Request-Id:f955e080-210b-4e60-9bb7-79deae62753e
X-Runtime:0.117768
X-XSS-Protection:1; mode=block
@FooBarWidget

This comment has been minimized.

Copy link
Member

commented Mar 4, 2016

Can you tell me which Rails version and Ruby version you are on?

We've received a support request from someone else who seems to be experiencing the same issue; he's also encoding to UTF-16LE though he uses 'render :text' instead of 'send_data'. Maybe the issue is related to a specific Rails version or Ruby version.

@fernandoluizao

This comment has been minimized.

Copy link
Author

commented Mar 4, 2016

ruby 2.2.4p230
rails 4.2.5.1

@fernandoluizao

This comment has been minimized.

Copy link
Author

commented Mar 4, 2016

I think this is related to some apache conf... cant reproduce this issue with passenger 5.0.26 standalone (same ruby/rails versions).

@fernandoluizao

This comment has been minimized.

Copy link
Author

commented Mar 4, 2016

I'm closing this issue as it seems that it's not passenger's related.

For now I will stick to v 5.0.25, but I will keep investigating what is causing this, and post updates here.

@FooBarWidget

This comment has been minimized.

Copy link
Member

commented Mar 4, 2016

The other person said that the issue goes way if he downgrades Passenger, and there was a change in 5.0.26 involving the Rack response handler, so it might actually be related. I'm reopening this issue until I've verified that it's not the case.

@OnixGH

This comment has been minimized.

Copy link
Contributor

commented Mar 7, 2016

It may or may not be related to Apache but do note that the other report we got was also with that integration mode.

@OnixGH

This comment has been minimized.

Copy link
Contributor

commented Mar 8, 2016

@fernandoluizao can you check if your log has an error about UTF-16LE encoding when the file is being requested? It should look something like this:

Exception Encoding::CompatibilityError in Rack response body object (incompatible character encodings: US-ASCII and UTF-16LE)

We think the error might occur in the backup routines that are used when native compilation fails (not a change in 5.0.26). That could explain why you see the issue only in the Apache mode and not in standalone (e.g. if standalone runs with a different user that doesn't fail compilation).

@fernandoluizao

This comment has been minimized.

Copy link
Author

commented Mar 10, 2016

@OnixGH yes, this error is in the apache logs.

Can I help with some more info or investigation?

@fernandoluizao

This comment has been minimized.

Copy link
Author

commented Mar 10, 2016

Here goes the full stack trace...

utils.rb:87 ]: *** Exception Encoding::CompatibilityError in Rack response body object (incompatible character encodings: US-ASCII and UTF-16LE) (process 1577, thread 0x000000013562f8(Worker 1)):
App 1558 stderr:        from /usr/lib/ruby/vendor_ruby/phusion_passenger/ruby_core_io_enhancements.rb:64:in `join'
App 1558 stderr:        from /usr/lib/ruby/vendor_ruby/phusion_passenger/ruby_core_io_enhancements.rb:64:in `writev'
App 1558 stderr:        from /usr/lib/ruby/vendor_ruby/phusion_passenger/utils/unseekable_socket.rb:127:in `writev'
App 1558 stderr:        from /usr/lib/ruby/vendor_ruby/phusion_passenger/rack/thread_handler_extension.rb:298:in `block in process_body'
App 1558 stderr:        from /var/www/mes-slitter/vendor/bundle/ruby/2.2.0/gems/rack-1.6.4/lib/rack/body_proxy.rb:31:in `each'
App 1558 stderr:        from /var/www/mes-slitter/vendor/bundle/ruby/2.2.0/gems/rack-1.6.4/lib/rack/body_proxy.rb:31:in `each'
App 1558 stderr:        from /var/www/mes-slitter/vendor/bundle/ruby/2.2.0/gems/rack-1.6.4/lib/rack/body_proxy.rb:31:in `each'
App 1558 stderr:        from /var/www/mes-slitter/vendor/bundle/ruby/2.2.0/gems/rack-1.6.4/lib/rack/body_proxy.rb:31:in `each'
App 1558 stderr:        from /var/www/mes-slitter/vendor/bundle/ruby/2.2.0/gems/rack-1.6.4/lib/rack/body_proxy.rb:31:in `each'
App 1558 stderr:        from /usr/lib/ruby/vendor_ruby/phusion_passenger/rack/thread_handler_extension.rb:295:in `process_body'
App 1558 stderr:        from /usr/lib/ruby/vendor_ruby/phusion_passenger/rack/thread_handler_extension.rb:146:in `process_request'
App 1558 stderr:        from /usr/lib/ruby/vendor_ruby/phusion_passenger/request_handler/thread_handler.rb:152:in `accept_and_process_next_request'
App 1558 stderr:        from /usr/lib/ruby/vendor_ruby/phusion_passenger/request_handler/thread_handler.rb:113:in `main_loop'
App 1558 stderr:        from /usr/lib/ruby/vendor_ruby/phusion_passenger/request_handler.rb:416:in `block (3 levels) in start_threads'
App 1558 stderr:        from /usr/lib/ruby/vendor_ruby/phusion_passenger/utils.rb:113:in `block in create_thread_and_abort_on_exception'
@OnixGH

This comment has been minimized.

Copy link
Contributor

commented Mar 10, 2016

@fernandoluizao thanks, that looks like what we thought it was. A fix is scheduled: c2e32ed

In the meantime you can work around the issue by ensuring that the native util compilation doesn't fail (see the logs for why it's failing, usually it's due to Passenger being started from a user that doesn't have enough access).

@fernandoluizao

This comment has been minimized.

Copy link
Author

commented Mar 10, 2016

@OnixGH that's the compilation error:

# current user is: fernando
# mkdir -p /usr/lib/buildout/ruby/ruby-2.2.4-x86_64-linux
Encountered permission error, trying a different directory...
-------------------------------
# mkdir -p /home/fernando/.passenger/native_support/5.0.26/ruby-2.2.4-x86_64-linux
# cd /home/fernando/.passenger/native_support/5.0.26/ruby-2.2.4-x86_64-linux
# /usr/bin/ruby2.2 /usr/lib/src/ruby_native_extension/extconf.rb
/usr/bin/ruby2.2: No such file or directory -- /usr/lib/src/ruby_native_extension/extconf.rb (LoadError)

I have installed passenger from your PPA. The packages shouldn't provide all the binaries already compiled? What it's trying to compile?

Many thanks, you guys are the best!

@OnixGH

This comment has been minimized.

Copy link
Contributor

commented Mar 10, 2016

We provide the essential binaries from our repo. The ruby native extensions that are getting compiled just give a very small performance boost so they are optional.

It just happens that in this case the native code handles the encodings better than the non-native code so having compilation succeed avoids the issue.

5.0.25 had the same code, but maybe something changed in 5.0.26 such that the native compilation stopped working for you, I'll to discuss that with @FooBarWidget. Can you confirm that 5.0.25 did have working compilation for you (with the same environment / user, etc.)?

@fernandoluizao

This comment has been minimized.

Copy link
Author

commented Mar 10, 2016

I confirm that 5.0.25 compiles correctly in the same environment.

@OnixGH OnixGH removed the SupportCentral label Mar 10, 2016

OnixGH pushed a commit that referenced this issue Mar 10, 2016

Daniel Knoppel (Phusion)
Fix encoding issue in Ruby non-nativeutils. Closes GH-1763.
The "backup" to the Ruby native utils could not handle mixed encodings
in the response body (e.g. UTF-8 and UTF-16) and caused an error,
leading to a zero byte response body.

@OnixGH OnixGH closed this in 4a0e281 Mar 10, 2016

@OnixGH

This comment has been minimized.

Copy link
Contributor

commented Mar 10, 2016

It looks like there's indeed a packaging issue in 5.0.26: ruby_native_extension doesn't look like the correct folder, but as a temporary fix to get the compilation going you could just copy the necessary files there anyway, e.g.:
cp -dpR /usr/share/passenger-enterprise/ruby_extension_source /usr/lib/src/ruby_native_extension

@FooBarWidget

This comment has been minimized.

Copy link
Member

commented Mar 19, 2016

@fernandoluizao I'm trying to solve the native extension compilation problem. Could you help me by providing some information that I need? Please refer to #1778 (comment), run the command that I posted at the end of that comment, and tell me what you see (in that thread).

@FooBarWidget

This comment has been minimized.

Copy link
Member

commented Mar 20, 2016

Never mind, I've been able to fix the compilation issue. :)

@cdcooksey

This comment has been minimized.

Copy link

commented Aug 19, 2017

@FooBarWidget What was the resolution to this issue?

@CamJN

This comment has been minimized.

Copy link
Contributor

commented Aug 21, 2017

This was fixed in 4a0e281, you can see the message in the changelog for 5.0.27:

Fix encoding issue for Ruby apps that resulted in a 0-byte response body. This occurred when the Ruby native support lib was not used and the app outputted an encoding that doesn't mix with UTF-8 (like UTF-16). Closes GH-1763.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.