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

ERROR Rack::Lint::LintError: Response body must respond to each #544

Closed
tomasmiguez opened this issue Jan 12, 2023 · 4 comments
Closed

ERROR Rack::Lint::LintError: Response body must respond to each #544

tomasmiguez opened this issue Jan 12, 2023 · 4 comments

Comments

@tomasmiguez
Copy link

Hello, I was trying to add rack-mini-profiler to a web service that uses Rack and Webrick, but when trying to access a flamegraph by appending ?pp=flamegraph or ?pp=async-flamegraph to request, I get the following error:

[2023-01-12 12:55:02] ERROR Rack::Lint::LintError: Response body must respond to each
	/home/tomiguez/.rbenv/versions/2.7.2/gemsets/api/gems/rack-2.2.5/lib/rack/lint.rb:21:in `assert'
	/home/tomiguez/.rbenv/versions/2.7.2/gemsets/api/gems/rack-2.2.5/lib/rack/lint.rb:750:in `each'
	/home/tomiguez/.rbenv/versions/2.7.2/gemsets/api/gems/rack-2.2.5/lib/rack/body_proxy.rb:41:in `method_missing'
	/home/tomiguez/.rbenv/versions/2.7.2/gemsets/api/gems/rack-2.2.5/lib/rack/content_length.rb:26:in `call'
	/home/tomiguez/.rbenv/versions/2.7.2/gemsets/api/gems/rack-2.2.5/lib/rack/handler/webrick.rb:95:in `service'
	/home/tomiguez/.rbenv/versions/2.7.2/lib/ruby/2.7.0/webrick/httpserver.rb:140:in `service'
	/home/tomiguez/.rbenv/versions/2.7.2/lib/ruby/2.7.0/webrick/httpserver.rb:96:in `run'
	/home/tomiguez/.rbenv/versions/2.7.2/lib/ruby/2.7.0/webrick/server.rb:307:in `block in start_thread'

And the request response body is:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN">
<HTML>

<HEAD>
	<TITLE>Internal Server Error</TITLE>
</HEAD>

<BODY>
	<H1>Internal Server Error</H1>
	Response body must respond to each
	<HR>
	<ADDRESS>
		WEBrick/1.6.0 (Ruby/2.7.2/2020-10-01) at
		localhost:9291
	</ADDRESS>
</BODY>

</HTML>

Thanks!

@gmcgibbon
Copy link
Contributor

I believe #547 is the problem. That patch should fix the problem, but in the meantime, you need to add stackprof to your app (see README).

@tomasmiguez
Copy link
Author

Hmm, I've already installed stackprof, it's in my gemfile and I ran bundle install on that project, but still the problem persists, and it seems it's related to it not detecting stackprof. I ran the program on an environment that doesn't use Rack::Lint and i get a different error:

[2023-02-09 15:07:10] ERROR NoMethodError: undefined method `each' for "Please install the stackprof gem and require it: add gem 'stackprof' to your Gemfile":String
	/home/tomiguez/.rbenv/versions/3.2.0/gemsets/api/gems/rack-2.2.6.2/lib/rack/body_proxy.rb:41:in `method_missing'
	/home/tomiguez/.rbenv/versions/3.2.0/gemsets/api/gems/rack-2.2.6.2/lib/rack/handler/webrick.rb:119:in `service'
	/home/tomiguez/.rbenv/versions/3.2.0/gemsets/api/gems/webrick-1.7.0/lib/webrick/httpserver.rb:140:in `service'
	/home/tomiguez/.rbenv/versions/3.2.0/gemsets/api/gems/webrick-1.7.0/lib/webrick/httpserver.rb:96:in `run'
	/home/tomiguez/.rbenv/versions/3.2.0/gemsets/api/gems/webrick-1.7.0/lib/webrick/server.rb:310:in `block in start_thread'

But I'm sure it's installed, this is what I get when running bundle install:

Using rake 13.0.1
Using concurrent-ruby 1.2.0
Using i18n 1.12.0
Using minitest 5.11.3
Using tzinfo 2.0.5
Using activesupport 7.0.4.2
Using public_suffix 4.0.5
Using addressable 2.7.0
Using builder 3.2.4
Using racc 1.6.2
Using nokogiri 1.14.0 (x86_64-linux)
Using rexml 3.2.5
Using gyoku 1.4.0
Using akami 1.3.1
Using rack 2.2.6.2
Using socksify 1.7.1
Using httpi 2.5.0
Using nori 2.6.0
Using wasabi 3.5.0
Using savon 2.11.2
Using afipws 1.3.2
Using armor 0.0.3
Using ast 2.4.2
Using aws-eventstream 1.1.1
Using aws-partitions 1.443.0
Using aws-sigv4 1.2.3
Using jmespath 1.4.0
Using aws-sdk-core 3.113.1
Using aws-sdk-kms 1.43.0
Using aws-sdk-s3 1.93.0
Using bugsnag 6.25.1
Using bundler 2.4.5
Using chunky_png 1.4.0
Using connection_pool 2.3.0
Using crc 0.4.1
Using cuba 3.9.2
Using io-console 0.6.0
Using reline 0.3.2
Using irb 1.6.2
Using debug 1.7.1
Using unf_ext 0.0.7.7
Using unf 0.1.4
Using domain_name 0.5.20190701
Using multipart-post 2.2.3
Using faraday 0.17.6
Using ffi 1.15.5
Using ffi-compiler 1.0.1
Using fixture_dependencies 1.11.0
Using http-cookie 1.0.3
Using http-form_data 2.3.0
Using http-parser 1.2.1
Using http 4.4.1
Using httpclient 2.8.3
Using json 1.8.6
Using jwt 2.2.1
Using kgio 2.11.4
Using rb-fsevent 0.11.2
Using rb-inotify 0.10.1
Using listen 3.8.0
Using matrix 0.4.2
Using mercadopago 3.0.0 from https://github.com/ombulabs/mercadopago.git
Using mini_magick 4.11.0
Using minitest-stub_any_instance 1.0.3
Using mono_logger 1.1.1
Using multi_json 1.15.0
Using ruby2_keywords 0.0.5
Using mustermann 3.0.0
Using parallel 1.22.1
Using parser 3.2.0.0
Using xml-simple 1.1.5
Using paypal-sdk-rest 1.7.4
Using pdf-core 0.9.0
Using pg 1.4.5
Using ttfunk 1.7.0
Using prawn 2.4.0
Using prawn-table 0.2.2
Using pundit 1.1.0
Using pusher-signature 0.1.8
Using pusher 1.3.3
Using rack-cors 1.1.1
Using rack-mini-profiler 3.0.0
Using rack-parser 0.7.0
Using rack-protection 3.0.5
Using rack-test 2.0.2
Using rainbow 3.1.1
Using raindrops 0.20.0
Using redis-client 0.12.1
Using redis 5.0.5
Using redis-namespace 1.10.0
Using regexp_parser 2.6.2
Using rerun 0.14.0
Using tilt 2.0.9
Using sinatra 3.0.5
Using resque 2.4.0
Using rqrcode_core 1.2.0
Using rqrcode 2.1.2
Using rubocop-ast 1.24.1
Using ruby-progressbar 1.11.0
Using unicode-display_width 2.4.2
Using rubocop 1.31.0
Using ruby-ole 1.2.12.2
Using rubyzip 2.3.0
Using rubyXL 3.4.14
Using scrivener 0.4.1
Using sequel 5.64.0
Using sequel_pg 1.17.1
Using shield 2.1.1
Using spreadsheet 1.2.6
Using stackprof 0.2.23
Using unicorn 6.1.0
Using webrick 1.7.0
Using yajl-ruby 1.4.3
Bundle complete! 47 Gemfile dependencies, 112 gems now installed.

Could it be something else? We are currently running Ruby 3.2.0, or maybe a gem version?

Thanks!

@gmcgibbon
Copy link
Contributor

The check done before profiling is

unless defined?(StackProf) && StackProf.respond_to?(:run)
so I would make sure that works in your env before trying to profile. I would guess it is either because you aren't requiring stackprof (eg. gem "stackprof", require: false, or you're using the wrong gem group (eg. it is grouped under development and you're trying to use it in production, but this might no apply for a sinatra app).

@tomasmiguez
Copy link
Author

Thanks! I was able to fix it after checking there. The problem was that in that project we don't use bundler.require, so I had to manually require the gem.

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

No branches or pull requests

2 participants