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

403 Forbidden on retries #4872

Closed
maxrosecollins opened this issue Apr 10, 2021 · 12 comments
Closed

403 Forbidden on retries #4872

maxrosecollins opened this issue Apr 10, 2021 · 12 comments

Comments

@maxrosecollins
Copy link

Ruby version: 2.7.2
Rails version: 6.1.3.1
Sidekiq version: 6.2.1
Sidekiq Pro version: 5.2.2

I am getting 403 forbidden error when retrying jobs.

I had the following set, but it doesn't seem to work any more?

Sidekiq::Web.set :session_secret, Rails.application.credentials.secret_key_base
Sidekiq::Web.set :sessions, Rails.application.config.session_options
@mperham
Copy link
Collaborator

mperham commented Apr 10, 2021

Please see the change log.

@maxrosecollins
Copy link
Author

maxrosecollins commented Apr 10, 2021

Yes, I have the following

config/initializers/sidekiq.rb

require 'sidekiq'
require 'sidekiq/web'
require 'sidekiq/scheduler'
require 'sidekiq-status'
require 'sidekiq-scheduler/web'
require 'sidekiq-status/web'

Sidekiq::Web.set :session_secret, Rails.application.secret_key_base

Sidekiq::Web.use(Rack::Auth::Basic) do |user, password|
  [user, password] == %w[******* ******]
end

Sidekiq::Client.reliable_push! unless Rails.env.test?

Sidekiq.configure_client do |config|
  config.redis = { url: "#{ENV['REDIS_SIDEKIQ_URL_INT']}" }
end
Sidekiq.configure_server do |config|
  config.redis = { url: "#{ENV['REDIS_SIDEKIQ_URL_INT']}" }
  config.super_fetch!
  config.reliable_scheduler!
end

routes.rb

require 'sidekiq/pro/web'
require 'sidekiq_unique_jobs/web'

# Configure Sidekiq-specific session middleware
Sidekiq::Web.use ActionDispatch::Cookies
Sidekiq::Web.use Rails.application.config.session_store, Rails.application.config.session_options

Rails.application.routes.draw do
  mount ActionCable.server => '/cable'
  mount Sidekiq::Web => '/sidekiq'
...

config/application.rb

# This also configures session_options for use below
    config.session_store :cookie_store, key: '_interslice_session'

    # Required for all session management (regardless of session_store)
    config.middleware.use ActionDispatch::Cookies

    config.middleware.use config.session_store, config.session_options

What am I missing?

@maxrosecollins
Copy link
Author

maxrosecollins commented Apr 10, 2021

If I run bin/rails middleware I get the following

bin/rails middleware
warning: parser/current is loading parser/ruby27, which recognizes
warning: 2.7.3-compliant syntax, but you are running 2.7.2.
warning: please see https://github.com/whitequark/parser#compatibility-with-ruby-mri.
appsignal: An error occured while loading the AppSignal config file. Skipping file config.
File: "/Users/max/Projects/ranktracker-api/config/appsignal.yml"
Psych::SyntaxError: (<unknown>): did not find expected key while parsing a block mapping at line 1 column 1
WARNING: Sidekiq::Web.session_secret= is no longer relevant and will be removed in Sidekiq 7.0. /Users/max/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/sidekiq-6.2.1/lib/sidekiq/web.rb:75:in `set'
WARNING: Sidekiq::Web.sessions= is no longer relevant and will be removed in Sidekiq 7.0. /Users/max/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/sidekiq-6.2.1/lib/sidekiq/web.rb:75:in `set'
use Rack::Cors
use ActionDispatch::HostAuthorization
use Rack::Sendfile
use ActionDispatch::Static
use ActionDispatch::Executor
use ActiveSupport::Cache::Strategy::LocalCache::Middleware
use Rack::Runtime
use ActionDispatch::RequestId
use ActionDispatch::RemoteIp
use Rails::Rack::Logger
use ActionDispatch::ShowExceptions
use ActionDispatch::DebugExceptions
use BetterErrors::Middleware
use Appsignal::Rack::RailsInstrumentation
use ActionDispatch::ActionableExceptions
use ActionDispatch::Reloader
use ActionDispatch::Callbacks
use ActiveRecord::Migration::CheckPending
use Rack::Head
use Rack::ConditionalGet
use Rack::ETag
use ActiveRecord::Middleware::DatabaseSelector
use ActionDispatch::Cookies
use ActionDispatch::Session::CookieStore
run RanktrackerApi::Application.routes

@mperham
Copy link
Collaborator

mperham commented Apr 10, 2021

Is your app a Rails API app?

@maxrosecollins
Copy link
Author

Yes, it is.

@mperham
Copy link
Collaborator

mperham commented Apr 10, 2021

Pro tip #1: Don't load any web stuff in config/initializers/sidekiq.rb. You don't need any web stuff for rails console, rake tasks, etc so all it does is slow down your boot. Put it all in routes.rb.

Pro tip #2: A frequent way that people break their own stuff is overconfiguring things. Remove all your Sidekiq::Web session config. You've added the sessions to your Rails app so you don't need any session config for Sidekiq::Web.

@maxrosecollins
Copy link
Author

maxrosecollins commented Apr 12, 2021

Okay, so I am getting an error

F, [2021-04-12T09:20:34.579998 #33] FATAL -- : [389c9875-8447-43d7-9e18-bde804be0f4a]
web-74b87b954b-tqv78 — [389c9875-8447-43d7-9e18-bde804be0f4a] NoMethodError (undefined method `[]=' for nil:NilClass):
web-74b87b954b-tqv78 — [389c9875-8447-43d7-9e18-bde804be0f4a]
web-74b87b954b-tqv78 — [389c9875-8447-43d7-9e18-bde804be0f4a] actionpack (6.1.3.1) lib/action_dispatch/request/session.rb:235:in `load!'
web-74b87b954b-tqv78 — [389c9875-8447-43d7-9e18-bde804be0f4a] actionpack (6.1.3.1) lib/action_dispatch/request/session.rb:230:in `load_for_write!'
web-74b87b954b-tqv78 — [389c9875-8447-43d7-9e18-bde804be0f4a] actionpack (6.1.3.1) lib/action_dispatch/request/session.rb:216:in `merge!'
web-74b87b954b-tqv78 — [389c9875-8447-43d7-9e18-bde804be0f4a] actionpack (6.1.3.1) lib/action_dispatch/request/session.rb:19:in `create'
web-74b87b954b-tqv78 — [389c9875-8447-43d7-9e18-bde804be0f4a] actionpack (6.1.3.1) lib/action_dispatch/middleware/session/abstract_store.rb:71:in `prepare_session'
web-74b87b954b-tqv78 — [389c9875-8447-43d7-9e18-bde804be0f4a] rack (2.2.3) lib/rack/session/abstract/id.rb:265:in `context'
web-74b87b954b-tqv78 — [389c9875-8447-43d7-9e18-bde804be0f4a] rack (2.2.3) lib/rack/session/abstract/id.rb:260:in `call'
web-74b87b954b-tqv78 — [389c9875-8447-43d7-9e18-bde804be0f4a] actionpack (6.1.3.1) lib/action_dispatch/middleware/cookies.rb:689:in `call'
web-74b87b954b-tqv78 — [389c9875-8447-43d7-9e18-bde804be0f4a] rack (2.2.3) lib/rack/static.rb:161:in `call'
web-74b87b954b-tqv78 — [389c9875-8447-43d7-9e18-bde804be0f4a] rack (2.2.3) lib/rack/builder.rb:244:in `call'
web-74b87b954b-tqv78 — [389c9875-8447-43d7-9e18-bde804be0f4a] sidekiq (6.2.1) lib/sidekiq/web.rb:108:in `call'
web-74b87b954b-tqv78 — [389c9875-8447-43d7-9e18-bde804be0f4a] sidekiq (6.2.1) lib/sidekiq/web.rb:113:in `call'
web-74b87b954b-tqv78 — [389c9875-8447-43d7-9e18-bde804be0f4a] actionpack (6.1.3.1) lib/action_dispatch/routing/mapper.rb:20:in `block in <class:Constraints>'
web-74b87b954b-tqv78 — [389c9875-8447-43d7-9e18-bde804be0f4a] actionpack (6.1.3.1) lib/action_dispatch/routing/mapper.rb:49:in `serve'
web-74b87b954b-tqv78 — [389c9875-8447-43d7-9e18-bde804be0f4a] actionpack (6.1.3.1) lib/action_dispatch/journey/router.rb:50:in `block in serve'
web-74b87b954b-tqv78 — [389c9875-8447-43d7-9e18-bde804be0f4a] actionpack (6.1.3.1) lib/action_dispatch/journey/router.rb:32:in `each'
web-74b87b954b-tqv78 — [389c9875-8447-43d7-9e18-bde804be0f4a] actionpack (6.1.3.1) lib/action_dispatch/journey/router.rb:32:in `serve'
web-74b87b954b-tqv78 — [389c9875-8447-43d7-9e18-bde804be0f4a] actionpack (6.1.3.1) lib/action_dispatch/routing/route_set.rb:842:in `call'
web-74b87b954b-tqv78 — [389c9875-8447-43d7-9e18-bde804be0f4a] activerecord (6.1.3.1) lib/active_record/middleware/database_selector.rb:53:in `block in call'
web-74b87b954b-tqv78 — [389c9875-8447-43d7-9e18-bde804be0f4a] activerecord (6.1.3.1) lib/active_record/middleware/database_selector/resolver.rb:63:in `block (2 levels) in read_from_replica'
web-74b87b954b-tqv78 — [389c9875-8447-43d7-9e18-bde804be0f4a] activesupport (6.1.3.1) lib/active_support/notifications/instrumenter.rb:24:in `instrument'
web-74b87b954b-tqv78 — [389c9875-8447-43d7-9e18-bde804be0f4a] activerecord (6.1.3.1) lib/active_record/middleware/database_selector/resolver.rb:62:in `block in read_from_replica'
web-74b87b954b-tqv78 — [389c9875-8447-43d7-9e18-bde804be0f4a] activerecord (6.1.3.1) lib/active_record/connection_handling.rb:383:in `block (2 levels) in with_role_and_shard'
web-74b87b954b-tqv78 — [389c9875-8447-43d7-9e18-bde804be0f4a] activerecord (6.1.3.1) lib/active_record/connection_adapters/abstract/connection_pool.rb:1025:in `while_preventing_writes'
web-74b87b954b-tqv78 — [389c9875-8447-43d7-9e18-bde804be0f4a] activerecord (6.1.3.1) lib/active_record/connection_handling.rb:381:in `block in with_role_and_shard'
web-74b87b954b-tqv78 — [389c9875-8447-43d7-9e18-bde804be0f4a] activerecord (6.1.3.1) lib/active_record/connection_handling.rb:398:in `swap_connection_handler'
web-74b87b954b-tqv78 — [389c9875-8447-43d7-9e18-bde804be0f4a] activerecord (6.1.3.1) lib/active_record/connection_handling.rb:373:in `with_handler'
web-74b87b954b-tqv78 — [389c9875-8447-43d7-9e18-bde804be0f4a] activerecord (6.1.3.1) lib/active_record/connection_handling.rb:380:in `with_role_and_shard'
web-74b87b954b-tqv78 — [389c9875-8447-43d7-9e18-bde804be0f4a] activerecord (6.1.3.1) lib/active_record/connection_handling.rb:175:in `connected_to'
web-74b87b954b-tqv78 — [389c9875-8447-43d7-9e18-bde804be0f4a] activerecord (6.1.3.1) lib/active_record/middleware/database_selector/resolver.rb:61:in `read_from_replica'
web-74b87b954b-tqv78 — [389c9875-8447-43d7-9e18-bde804be0f4a] activerecord (6.1.3.1) lib/active_record/middleware/database_selector/resolver.rb:39:in `read'
web-74b87b954b-tqv78 — [389c9875-8447-43d7-9e18-bde804be0f4a] activerecord (6.1.3.1) lib/active_record/middleware/database_selector.rb:63:in `select_database'
web-74b87b954b-tqv78 — [389c9875-8447-43d7-9e18-bde804be0f4a] activerecord (6.1.3.1) lib/active_record/middleware/database_selector.rb:52:in `call'
web-74b87b954b-tqv78 — [389c9875-8447-43d7-9e18-bde804be0f4a] rack (2.2.3) lib/rack/etag.rb:27:in `call'
web-74b87b954b-tqv78 — [389c9875-8447-43d7-9e18-bde804be0f4a] rack (2.2.3) lib/rack/conditional_get.rb:27:in `call'
web-74b87b954b-tqv78 — [389c9875-8447-43d7-9e18-bde804be0f4a] rack (2.2.3) lib/rack/head.rb:12:in `call'
web-74b87b954b-tqv78 — [389c9875-8447-43d7-9e18-bde804be0f4a] actionpack (6.1.3.1) lib/action_dispatch/middleware/callbacks.rb:27:in `block in call'
web-74b87b954b-tqv78 — [389c9875-8447-43d7-9e18-bde804be0f4a] activesupport (6.1.3.1) lib/active_support/callbacks.rb:98:in `run_callbacks'
web-74b87b954b-tqv78 — [389c9875-8447-43d7-9e18-bde804be0f4a] actionpack (6.1.3.1) lib/action_dispatch/middleware/callbacks.rb:26:in `call'
web-74b87b954b-tqv78 — [389c9875-8447-43d7-9e18-bde804be0f4a] actionpack (6.1.3.1) lib/action_dispatch/middleware/executor.rb:14:in `call'
web-74b87b954b-tqv78 — [389c9875-8447-43d7-9e18-bde804be0f4a] actionpack (6.1.3.1) lib/action_dispatch/middleware/actionable_exceptions.rb:18:in `call'
web-74b87b954b-tqv78 — [389c9875-8447-43d7-9e18-bde804be0f4a] appsignal (3.0.2) lib/appsignal/rack/rails_instrumentation.rb:32:in `call_with_appsignal_monitoring'
web-74b87b954b-tqv78 — [389c9875-8447-43d7-9e18-bde804be0f4a] appsignal (3.0.2) lib/appsignal/rack/rails_instrumentation.rb:17:in `call'
web-74b87b954b-tqv78 — [389c9875-8447-43d7-9e18-bde804be0f4a] actionpack (6.1.3.1) lib/action_dispatch/middleware/debug_exceptions.rb:29:in `call'
web-74b87b954b-tqv78 — [389c9875-8447-43d7-9e18-bde804be0f4a] actionpack (6.1.3.1) lib/action_dispatch/middleware/show_exceptions.rb:33:in `call'
web-74b87b954b-tqv78 — [389c9875-8447-43d7-9e18-bde804be0f4a] railties (6.1.3.1) lib/rails/rack/logger.rb:37:in `call_app'
web-74b87b954b-tqv78 — [389c9875-8447-43d7-9e18-bde804be0f4a] railties (6.1.3.1) lib/rails/rack/logger.rb:26:in `block in call'
web-74b87b954b-tqv78 — [389c9875-8447-43d7-9e18-bde804be0f4a] activesupport (6.1.3.1) lib/active_support/tagged_logging.rb:99:in `block in tagged'
web-74b87b954b-tqv78 — [389c9875-8447-43d7-9e18-bde804be0f4a] activesupport (6.1.3.1) lib/active_support/tagged_logging.rb:37:in `tagged'
web-74b87b954b-tqv78 — [389c9875-8447-43d7-9e18-bde804be0f4a] activesupport (6.1.3.1) lib/active_support/tagged_logging.rb:99:in `tagged'
web-74b87b954b-tqv78 — [389c9875-8447-43d7-9e18-bde804be0f4a] railties (6.1.3.1) lib/rails/rack/logger.rb:26:in `call'
web-74b87b954b-tqv78 — [389c9875-8447-43d7-9e18-bde804be0f4a] actionpack (6.1.3.1) lib/action_dispatch/middleware/remote_ip.rb:81:in `call'
web-74b87b954b-tqv78 — [389c9875-8447-43d7-9e18-bde804be0f4a] actionpack (6.1.3.1) lib/action_dispatch/middleware/request_id.rb:26:in `call'
web-74b87b954b-tqv78 — [389c9875-8447-43d7-9e18-bde804be0f4a] rack (2.2.3) lib/rack/runtime.rb:22:in `call'
web-74b87b954b-tqv78 — [389c9875-8447-43d7-9e18-bde804be0f4a] activesupport (6.1.3.1) lib/active_support/cache/strategy/local_cache_middleware.rb:29:in `call'
web-74b87b954b-tqv78 — [389c9875-8447-43d7-9e18-bde804be0f4a] actionpack (6.1.3.1) lib/action_dispatch/middleware/executor.rb:14:in `call'
web-74b87b954b-tqv78 — [389c9875-8447-43d7-9e18-bde804be0f4a] rack (2.2.3) lib/rack/sendfile.rb:110:in `call'
web-74b87b954b-tqv78 — [389c9875-8447-43d7-9e18-bde804be0f4a] actionpack (6.1.3.1) lib/action_dispatch/middleware/host_authorization.rb:92:in `call'
web-74b87b954b-tqv78 — [389c9875-8447-43d7-9e18-bde804be0f4a] rack-cors (1.1.1) lib/rack/cors.rb:100:in `call'
web-74b87b954b-tqv78 — [389c9875-8447-43d7-9e18-bde804be0f4a] railties (6.1.3.1) lib/rails/engine.rb:539:in `call'
web-74b87b954b-tqv78 — [389c9875-8447-43d7-9e18-bde804be0f4a] puma (5.2.2) lib/puma/configuration.rb:248:in `call'
web-74b87b954b-tqv78 — [389c9875-8447-43d7-9e18-bde804be0f4a] puma (5.2.2) lib/puma/request.rb:76:in `block in handle_request'
web-74b87b954b-tqv78 — [389c9875-8447-43d7-9e18-bde804be0f4a] puma (5.2.2) lib/puma/thread_pool.rb:337:in `with_force_shutdown'
web-74b87b954b-tqv78 — [389c9875-8447-43d7-9e18-bde804be0f4a] puma (5.2.2) lib/puma/request.rb:75:in `handle_request'
web-74b87b954b-tqv78 — [389c9875-8447-43d7-9e18-bde804be0f4a] puma (5.2.2) lib/puma/server.rb:431:in `process_client'
web-74b87b954b-tqv78 — [389c9875-8447-43d7-9e18-bde804be0f4a] puma (5.2.2) lib/puma/thread_pool.rb:145:in `block in spawn_thread'
web-74b87b954b-j8pbj — [564a856e-9bfb-45e9-ba16-a2fa8d4ed391] rack (2.2.3) lib/rack/head.rb:12:in `call'
web-74b87b954b-j8pbj — [564a856e-9bfb-45e9-ba16-a2fa8d4ed391] actionpack (6.1.3.1) lib/action_dispatch/middleware/callbacks.rb:27:in `block in call'
web-74b87b954b-j8pbj — [564a856e-9bfb-45e9-ba16-a2fa8d4ed391] activesupport (6.1.3.1) lib/active_support/callbacks.rb:98:in `run_callbacks'
web-74b87b954b-j8pbj — [564a856e-9bfb-45e9-ba16-a2fa8d4ed391] actionpack (6.1.3.1) lib/action_dispatch/middleware/callbacks.rb:26:in `call'
web-74b87b954b-j8pbj — [564a856e-9bfb-45e9-ba16-a2fa8d4ed391] actionpack (6.1.3.1) lib/action_dispatch/middleware/executor.rb:14:in `call'
web-74b87b954b-j8pbj — [564a856e-9bfb-45e9-ba16-a2fa8d4ed391] actionpack (6.1.3.1) lib/action_dispatch/middleware/actionable_exceptions.rb:18:in `call'
web-74b87b954b-j8pbj — [564a856e-9bfb-45e9-ba16-a2fa8d4ed391] appsignal (3.0.2) lib/appsignal/rack/rails_instrumentation.rb:32:in `call_with_appsignal_monitoring'
web-74b87b954b-j8pbj — [564a856e-9bfb-45e9-ba16-a2fa8d4ed391] appsignal (3.0.2) lib/appsignal/rack/rails_instrumentation.rb:17:in `call'
web-74b87b954b-j8pbj — [564a856e-9bfb-45e9-ba16-a2fa8d4ed391] actionpack (6.1.3.1) lib/action_dispatch/middleware/debug_exceptions.rb:29:in `call'
web-74b87b954b-j8pbj — [564a856e-9bfb-45e9-ba16-a2fa8d4ed391] actionpack (6.1.3.1) lib/action_dispatch/middleware/show_exceptions.rb:33:in `call'
web-74b87b954b-j8pbj — [564a856e-9bfb-45e9-ba16-a2fa8d4ed391] railties (6.1.3.1) lib/rails/rack/logger.rb:37:in `call_app'
web-74b87b954b-j8pbj — [564a856e-9bfb-45e9-ba16-a2fa8d4ed391] railties (6.1.3.1) lib/rails/rack/logger.rb:26:in `block in call'
web-74b87b954b-j8pbj — [564a856e-9bfb-45e9-ba16-a2fa8d4ed391] activesupport (6.1.3.1) lib/active_support/tagged_logging.rb:99:in `block in tagged'
web-74b87b954b-j8pbj — [564a856e-9bfb-45e9-ba16-a2fa8d4ed391] activesupport (6.1.3.1) lib/active_support/tagged_logging.rb:37:in `tagged'
web-74b87b954b-j8pbj — [564a856e-9bfb-45e9-ba16-a2fa8d4ed391] activesupport (6.1.3.1) lib/active_support/tagged_logging.rb:99:in `tagged'
web-74b87b954b-j8pbj — [564a856e-9bfb-45e9-ba16-a2fa8d4ed391] railties (6.1.3.1) lib/rails/rack/logger.rb:26:in `call'
web-74b87b954b-j8pbj — [564a856e-9bfb-45e9-ba16-a2fa8d4ed391] actionpack (6.1.3.1) lib/action_dispatch/middleware/remote_ip.rb:81:in `call'
web-74b87b954b-j8pbj — [564a856e-9bfb-45e9-ba16-a2fa8d4ed391] actionpack (6.1.3.1) lib/action_dispatch/middleware/request_id.rb:26:in `call'
web-74b87b954b-j8pbj — [564a856e-9bfb-45e9-ba16-a2fa8d4ed391] rack (2.2.3) lib/rack/runtime.rb:22:in `call'
web-74b87b954b-j8pbj — [564a856e-9bfb-45e9-ba16-a2fa8d4ed391] activesupport (6.1.3.1) lib/active_support/cache/strategy/local_cache_middleware.rb:29:in `call'
web-74b87b954b-j8pbj — [564a856e-9bfb-45e9-ba16-a2fa8d4ed391] actionpack (6.1.3.1) lib/action_dispatch/middleware/executor.rb:14:in `call'
web-74b87b954b-j8pbj — [564a856e-9bfb-45e9-ba16-a2fa8d4ed391] rack (2.2.3) lib/rack/sendfile.rb:110:in `call'
web-74b87b954b-j8pbj — [564a856e-9bfb-45e9-ba16-a2fa8d4ed391] actionpack (6.1.3.1) lib/action_dispatch/middleware/host_authorization.rb:92:in `call'
web-74b87b954b-j8pbj — [564a856e-9bfb-45e9-ba16-a2fa8d4ed391] rack-cors (1.1.1) lib/rack/cors.rb:100:in `call'
web-74b87b954b-j8pbj — [564a856e-9bfb-45e9-ba16-a2fa8d4ed391] railties (6.1.3.1) lib/rails/engine.rb:539:in `call'
web-74b87b954b-j8pbj — [564a856e-9bfb-45e9-ba16-a2fa8d4ed391] puma (5.2.2) lib/puma/configuration.rb:248:in `call'
web-74b87b954b-j8pbj — [564a856e-9bfb-45e9-ba16-a2fa8d4ed391] puma (5.2.2) lib/puma/request.rb:76:in `block in handle_request'
web-74b87b954b-j8pbj — [564a856e-9bfb-45e9-ba16-a2fa8d4ed391] puma (5.2.2) lib/puma/thread_pool.rb:337:in `with_force_shutdown'
web-74b87b954b-j8pbj — [564a856e-9bfb-45e9-ba16-a2fa8d4ed391] puma (5.2.2) lib/puma/request.rb:75:in `handle_request'
web-74b87b954b-j8pbj — [564a856e-9bfb-45e9-ba16-a2fa8d4ed391] puma (5.2.2) lib/puma/server.rb:431:in `process_client'
web-74b87b954b-j8pbj — [564a856e-9bfb-45e9-ba16-a2fa8d4ed391] puma (5.2.2) lib/puma/thread_pool.rb:145:in `block in spawn_thread'

@mperham
Copy link
Collaborator

mperham commented Apr 12, 2021 via email

@maxrosecollins
Copy link
Author

As it is a rails api, I believe there are no cookies?

I was looking at this

They mention you need to add something like the following.

config.middleware.use ActionDispatch::Cookies
config.middleware.use ActionDispatch::Session::CookieStore, key: '_your_app'
config.middleware.insert_after(ActionDispatch::Cookies, ActionDispatch::Session::CookieStore, key: '_your_app')

So I tried;

# This also configures session_options for use below
config.session_store :cookie_store, key: '_interslice_session'

# Required for all session management (regardless of session_store)
config.middleware.use ActionDispatch::Cookies
config.middleware.use ActionDispatch::Session::CookieStore, key: '_interslice_session'
config.middleware.insert_after(ActionDispatch::Cookies, ActionDispatch::Session::CookieStore, key: '_interslice_session')

config.middleware.use config.session_store, config.session_options

This doesn't work either...

As soon as I add config.middleware.use ActionDispatch::Cookies into the app it breaks.

@mperham
Copy link
Collaborator

mperham commented Apr 12, 2021 via email

@maxrosecollins
Copy link
Author

Yep, I will ask.

Interestingly, if I set config.api_only = true to config.api_only = false then it all works as expected so there must be an issue somewhere with the sessions not loading correctly in an api_only setup.

@mperham
Copy link
Collaborator

mperham commented May 3, 2021

Others have discovered that Rails API apps don't have a session middleware configured, so Forbidden happens. See https://guides.rubyonrails.org/api_app.html#using-session-middlewares for the solution; you'll need to install a session middleware somehow.

@mperham mperham closed this as completed May 3, 2021
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