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

stack level too deep (SystemStackError) on authenticate_or_request_with_http_token #8

Open
dtonon opened this issue Sep 26, 2023 · 4 comments

Comments

@dtonon
Copy link

dtonon commented Sep 26, 2023

rails_api_logger 0.6.3
rails 7.0.3


I'm getting this error when I call the API without, or with a wrong, authentication token:

class ApiController < ActionController::API
  include ActionController::HttpAuthentication::Token::ControllerMethods

  before_action :authenticate

  def authenticate
    authenticate_or_request_with_http_token do |token, _options|
      ActiveSupport::SecurityUtils.secure_compare(token, Rails.application.credentials.api_key)
    end
  end

  ....

end

application.rb

require_relative "boot"
require "rails/all"

Bundler.require(*Rails.groups)

module MyApp
  class Application < Rails::Application
    # Initialize configuration defaults for originally generated Rails version.
    config.load_defaults 7.0

    .....

    # log to InboundRequestsLoggerMiddleware only requests from /api
    config.middleware.insert_before Rails::Rack::Logger, InboundRequestsLoggerMiddleware, path_regexp: /api/

    ....

  end
end

The stacktrace:

Puma caught this error: stack level too deep (SystemStackError)
/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/activesupport-7.0.4.3/lib/active_support/core_ext/object/json.rb:179:in `each'
/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/activesupport-7.0.4.3/lib/active_support/core_ext/object/json.rb:179:in `as_json'
/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/activesupport-7.0.4.3/lib/active_support/core_ext/object/json.rb:63:in `as_json'
/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/activesupport-7.0.4.3/lib/active_support/core_ext/object/json.rb:180:in `block in as_json'
/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/activesupport-7.0.4.3/lib/active_support/core_ext/object/json.rb:179:in `each'
/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/activesupport-7.0.4.3/lib/active_support/core_ext/object/json.rb:179:in `as_json'
/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/activesupport-7.0.4.3/lib/active_support/core_ext/object/json.rb:63:in `as_json'

[ 2000+ repetitions ]

/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/activesupport-7.0.4.3/lib/active_support/core_ext/object/json.rb:180:in `block in as_json'
/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/activesupport-7.0.4.3/lib/active_support/core_ext/object/json.rb:179:in `each'
/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/activesupport-7.0.4.3/lib/active_support/core_ext/object/json.rb:179:in `as_json'
/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/activesupport-7.0.4.3/lib/active_support/core_ext/object/json.rb:63:in `as_json'
/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/activesupport-7.0.4.3/lib/active_support/core_ext/object/json.rb:180:in `block in as_json'
/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/activesupport-7.0.4.3/lib/active_support/core_ext/object/json.rb:179:in `each'
/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/activesupport-7.0.4.3/lib/active_support/core_ext/object/json.rb:179:in `as_json'
/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/activesupport-7.0.4.3/lib/active_support/core_ext/object/json.rb:63:in `as_json'
/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/activesupport-7.0.4.3/lib/active_support/json/encoding.rb:35:in `encode'
/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/activesupport-7.0.4.3/lib/active_support/json/encoding.rb:22:in `encode'
/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/activerecord-7.0.4.3/lib/active_record/coders/json.rb:7:in `dump'
/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/activerecord-7.0.4.3/lib/active_record/type/serialized.rb:29:in `serialize'
/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/activemodel-7.0.4.3/lib/active_model/attribute.rb:56:in `value_for_database'
/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/activemodel-7.0.4.3/lib/active_model/attribute.rb:72:in `forgetting_assignment'
/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/activemodel-7.0.4.3/lib/active_model/attribute_mutation_tracker.rb:55:in `forget_change'
/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/activemodel-7.0.4.3/lib/active_model/dirty.rb:251:in `clear_attribute_change'
/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/activerecord-7.0.4.3/lib/active_record/persistence.rb:819:in `block in update_columns'
/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/activerecord-7.0.4.3/lib/active_record/persistence.rb:817:in `each'
/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/activerecord-7.0.4.3/lib/active_record/persistence.rb:817:in `each_with_object'
/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/activerecord-7.0.4.3/lib/active_record/persistence.rb:817:in `update_columns'
/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rails_api_logger-0.6.3/lib/rails_api_logger/inbound_requests_logger_middleware.rb:19:in `call'
/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/actionpack-7.0.4.3/lib/action_dispatch/middleware/remote_ip.rb:93:in `call'
/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/request_store-1.5.1/lib/request_store/middleware.rb:19:in `call'
/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/actionpack-7.0.4.3/lib/action_dispatch/middleware/request_id.rb:26:in `call'
/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rack-2.2.8/lib/rack/method_override.rb:24:in `call'
/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rack-2.2.8/lib/rack/runtime.rb:22:in `call'
/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/activesupport-7.0.4.3/lib/active_support/cache/strategy/local_cache_middleware.rb:29:in `call'
/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/actionpack-7.0.4.3/lib/action_dispatch/middleware/server_timing.rb:61:in `block in call'
/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/actionpack-7.0.4.3/lib/action_dispatch/middleware/server_timing.rb:26:in `collect_events'
/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/actionpack-7.0.4.3/lib/action_dispatch/middleware/server_timing.rb:60:in `call'
/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/actionpack-7.0.4.3/lib/action_dispatch/middleware/executor.rb:14:in `call'
/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/actionpack-7.0.4.3/lib/action_dispatch/middleware/static.rb:23:in `call'
/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rack-2.2.8/lib/rack/sendfile.rb:110:in `call'
/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/actionpack-7.0.4.3/lib/action_dispatch/middleware/host_authorization.rb:137:in `call'
/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/railties-7.0.4.3/lib/rails/engine.rb:530:in `call'
/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/puma-6.2.1/lib/puma/configuration.rb:270:in `call'
/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/puma-6.2.1/lib/puma/request.rb:98:in `block in handle_request'
/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/puma-6.2.1/lib/puma/thread_pool.rb:340:in `with_force_shutdown'
/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/puma-6.2.1/lib/puma/request.rb:97:in `handle_request'
/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/puma-6.2.1/lib/puma/server.rb:431:in `process_client'
/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/puma-6.2.1/lib/puma/server.rb:233:in `block in run'
/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/puma-6.2.1/lib/puma/thread_pool.rb:147:in `block in spawn_thread'
@coorasse
Copy link
Member

coorasse commented Mar 4, 2024

Is this still happening in version 0.7.0? This should be solved now, please let me know.

@wooly
Copy link

wooly commented May 10, 2024

@coorasse this is happening for us for post requests made to our API that satisfy the following conditions:

  • There is no authentication header present
  • The API endpoint nonsense and the backend is a 404

@dtonon
Copy link
Author

dtonon commented Jun 3, 2024

Is this still happening in version 0.7.0? This should be solved now, please let me know.

Sorry for the late reply, I didn't update the gem yet, I will try

@coorasse
Copy link
Member

We released a new version (0.8.2) which should solve a similar problem when used in combination with Appsignal. See appsignal/appsignal-ruby#1265. Let me know if the problem is solved, please.

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

3 participants