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

Issue with 4.2.0 -> IPAddr::AddressFamilyError: address family must be specified #1274

Closed
johnernaut opened this issue Feb 5, 2021 · 2 comments · Fixed by #1288 or communitiesuk/epb-register-api#78
Assignees

Comments

@johnernaut
Copy link

Describe the bug
When running our application in production (via ECS and Fargate), we're seeing an application error which causes the process to die immediately. Here's an example taken from the logs:

Feb 05 13:04:52.630		rails	/var/www/homebase/vendor/bundle/ruby/2.6.0/gems/puma-3.12.6/lib/puma/thread_pool.rb:135:in `block in spawn_thread'
Feb 05 13:04:52.630		rails	/var/www/homebase/vendor/bundle/ruby/2.6.0/gems/puma-3.12.6/lib/puma/server.rb:334:in `block in run'
Feb 05 13:04:52.630		rails	/var/www/homebase/vendor/bundle/ruby/2.6.0/gems/puma-3.12.6/lib/puma/server.rb:476:in `process_client'
Feb 05 13:04:52.630		rails	/var/www/homebase/vendor/bundle/ruby/2.6.0/gems/puma-3.12.6/lib/puma/server.rb:706:in `handle_request'
Feb 05 13:04:52.630		rails	/var/www/homebase/vendor/bundle/ruby/2.6.0/gems/puma-3.12.6/lib/puma/configuration.rb:227:in `call'
Feb 05 13:04:52.630		rails	/var/www/homebase/vendor/bundle/ruby/2.6.0/gems/newrelic_rpm-6.8.0.360/lib/new_relic/agent/instrumentation/middleware_tracing.rb:99:in `call'
Feb 05 13:04:52.630		rails	/var/www/homebase/vendor/bundle/ruby/2.6.0/gems/railties-6.0.3.3/lib/rails/railtie.rb:190:in `method_missing'
Feb 05 13:04:52.630		rails	/var/www/homebase/vendor/bundle/ruby/2.6.0/gems/railties-6.0.3.3/lib/rails/railtie.rb:190:in `public_send'
Feb 05 13:04:52.629		rails	/var/www/homebase/vendor/bundle/ruby/2.6.0/gems/railties-6.0.3.3/lib/rails/engine.rb:527:in `call'
Feb 05 13:04:52.629		rails	/var/www/homebase/vendor/bundle/ruby/2.6.0/gems/newrelic_rpm-6.8.0.360/lib/new_relic/agent/instrumentation/middleware_tracing.rb:99:in `call'
Feb 05 13:04:52.629		rails	/var/www/homebase/vendor/bundle/ruby/2.6.0/gems/sentry-ruby-core-4.2.0/lib/sentry/rack/capture_exceptions.rb:14:in `call'
Feb 05 13:04:52.629		rails	/var/www/homebase/vendor/bundle/ruby/2.6.0/gems/sentry-ruby-core-4.2.0/lib/sentry-ruby.rb:149:in `with_scope'
Feb 05 13:04:52.629		rails	/var/www/homebase/vendor/bundle/ruby/2.6.0/gems/sentry-ruby-core-4.2.0/lib/sentry/hub.rb:52:in `with_scope'
Feb 05 13:04:52.629		rails	/var/www/homebase/vendor/bundle/ruby/2.6.0/gems/sentry-ruby-core-4.2.0/lib/sentry/rack/capture_exceptions.rb:42:in `block in call'
Feb 05 13:04:52.629		rails	/var/www/homebase/vendor/bundle/ruby/2.6.0/gems/sentry-rails-4.2.0/lib/sentry/rails/capture_exceptions.rb:35:in `finish_span'
Feb 05 13:04:52.629		rails	/var/www/homebase/vendor/bundle/ruby/2.6.0/gems/sentry-ruby-core-4.2.0/lib/sentry/transaction.rb:130:in `finish'
Feb 05 13:04:52.629		rails	/var/www/homebase/vendor/bundle/ruby/2.6.0/gems/sentry-ruby-core-4.2.0/lib/sentry/hub.rb:117:in `capture_event'
Feb 05 13:04:52.629		rails	/var/www/homebase/vendor/bundle/ruby/2.6.0/gems/sentry-ruby-core-4.2.0/lib/sentry/client.rb:26:in `capture_event'
Feb 05 13:04:52.629		rails	/var/www/homebase/vendor/bundle/ruby/2.6.0/gems/sentry-ruby-core-4.2.0/lib/sentry/scope.rb:34:in `apply_to_event'
Feb 05 13:04:52.629		rails	/var/www/homebase/vendor/bundle/ruby/2.6.0/gems/sentry-ruby-core-4.2.0/lib/sentry/event.rb:86:in `rack_env='
Feb 05 13:04:52.629		rails	/var/www/homebase/vendor/bundle/ruby/2.6.0/gems/sentry-ruby-core-4.2.0/lib/sentry/event.rb:171:in `calculate_real_ip_from_rack'
Feb 05 13:04:52.629		rails	/var/www/homebase/vendor/bundle/ruby/2.6.0/gems/sentry-ruby-core-4.2.0/lib/sentry/event.rb:171:in `new'
Feb 05 13:04:52.629		rails	/var/www/homebase/vendor/bundle/ruby/2.6.0/gems/sentry-ruby-core-4.2.0/lib/sentry/utils/real_ip.rb:32:in `initialize'
Feb 05 13:04:52.629		rails	/var/www/homebase/vendor/bundle/ruby/2.6.0/gems/sentry-ruby-core-4.2.0/lib/sentry/utils/real_ip.rb:32:in `map'
Feb 05 13:04:52.629		rails	/var/www/homebase/vendor/bundle/ruby/2.6.0/gems/sentry-ruby-core-4.2.0/lib/sentry/utils/real_ip.rb:32:in `block in initialize'
Feb 05 13:04:52.629		rails	/var/www/homebase/vendor/bundle/ruby/2.6.0/gems/sentry-ruby-core-4.2.0/lib/sentry/utils/real_ip.rb:32:in `new'
Feb 05 13:04:52.629		rails	/usr/lib/fullstaq-ruby/versions/2.6.5-jemalloc/lib/ruby/2.6.0/ipaddr.rb:565:in `initialize'
Feb 05 13:04:52.629		rails	#<IPAddr::AddressFamilyError: address family must be specified>
Feb 05 13:04:52.629		rails	2021-02-05 19:04:52 +0000: Rack app error handling request { GET /health_check }

This issue seems to stem from this line: https://github.com/getsentry/sentry-ruby/blob/master/sentry-ruby/lib/sentry/utils/real_ip.rb#L32

It's worth noting that we have trusted_proxies configured within our Rails app:

    proxies = %w(
      10.10.0.0/16
      20.10.0.0/16
      20.20.0.0/16
      20.30.0.0/16
      20.40.0.0/16
    )

    config.action_dispatch.trusted_proxies = proxies.map { |proxy| IPAddr.new(proxy) }

I tried to set the trusted_proxies configuration to the above array in the Sentry.init block in the initializer myself but the result was the same.

Environment

  • Ruby Version: 2.6.5
  • SDK Version: 4.2.0
  • Integration Versions (if any):
  • Rails 6.0

SentryConfig

Sentry.init do |config|
  config.dsn = ENV['SENTRY_DSN']
  config.breadcrumbs_logger = [:active_support_logger]
  config.rails.report_rescued_exceptions = true
  config.send_default_pii = true # send ip, cookie, request body
  config.enabled_environments = %w(staging production)
  config.traces_sample_rate = 0.5
end
@woidda
Copy link

woidda commented Feb 15, 2021

Should related to the mentioned trusted_proxies.

Trying in a rails console:

Sentry::Utils::RealIp.new(
        :remote_addr => nil,
        :client_ip => nil,
        :real_ip => nil,
        :forwarded_for => nil,
        :trusted_proxies => [nil]
      ).calculate_ip

leads to this issue

IPAddr::AddressFamilyError (address family must be specified)

@st0012 st0012 added this to the sentry-ruby-4.2.2 milestone Feb 15, 2021
@woidda
Copy link

woidda commented Feb 15, 2021

:trusted_proxies => [pr]
It seems that pr must be a string, but not an IPAddr object, such as <IPAddr: IPv4:127.0.0.1/255.255.255.255>.
quick fix would be to map all trusted_proxies that you get from rails via a .to_s. This does not create issues if the trusted_proxies is an array of strings already.

gagalago added a commit to sortlist/sentry-ruby that referenced this issue Feb 15, 2021
fix getsentry#1274

`IPAddr.new` only accept the address as a string but not as an `IPAddr` as suggested in the Rails documentation https://api.rubyonrails.org/classes/ActionDispatch/RemoteIp.html
st0012 pushed a commit that referenced this issue Feb 16, 2021
* always convert trusted proxies to string

fix #1274

`IPAddr.new` only accept the address as a string but not as an `IPAddr` as suggested in the Rails documentation https://api.rubyonrails.org/classes/ActionDispatch/RemoteIp.html

* remove railtie fix

* add test for IPAddr trusted proxies

* convert proxy ip to string before IPAddr

* update changelog
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment