Skip to content

fix(rails): don't load ActionController::Live before initialization - #3109

Open
ajaynomics wants to merge 1 commit into
getsentry:masterfrom
ajaynomics:fix-rails-live-load-hook
Open

ajaynomics wants to merge 1 commit into
getsentry:masterfrom
ajaynomics:fix-rails-live-load-hook

Conversation

@ajaynomics

Copy link
Copy Markdown

Description

Under Rails 8.1 with eager_load off (rake tasks, console, most dev boots), sentry-rails makes Rails print:

:action_dispatch_response was loaded before application initialization

The railtie referenced ActionController::Live inside the :action_controller load hook to prepend StreamingReporter. That reference autoloads ActionController::Live, which loads ActionDispatch::Response too early, and Rails warns.

Rails 8.1.4 added an :action_controller_live load hook. This PR prepends the reporter from that hook, so nothing touches ActionController::Live until the app does. On older Rails the direct reference stays.

Tested with a new isolated spec, sentry-rails/spec/isolated/streaming_reporter_spec.rb. It asserts the reporter is still prepended, and boots a bare app in a child process to assert initialization leaves ActionController::Live unloaded. The second example fails on master and passes here. spec/isolated and spec/sentry pass on the ruby-3.4_rails-8.1.3 cell; RuboCop is clean on both files.

Referencing ActionController::Live in the railtie loads ActionDispatch::Response
before the application has initialized, which Rails 8.1 warns about when
eager loading is off. Use the :action_controller_live load hook that Rails
8.1.4 added, and keep the direct reference on older versions.
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

Successfully merging this pull request may close these issues.

sentry-rails triggers "Prematurely executing load hooks" warning for :action_dispatch_response on Rails 8.2

1 participant