fix(rails): don't load ActionController::Live before initialization - #3109
Open
ajaynomics wants to merge 1 commit into
Open
ajaynomics wants to merge 1 commit into
ajaynomics wants to merge 1 commit into
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Under Rails 8.1 with
eager_loadoff (rake tasks, console, most dev boots), sentry-rails makes Rails print:The railtie referenced
ActionController::Liveinside the:action_controllerload hook to prependStreamingReporter. That reference autoloadsActionController::Live, which loadsActionDispatch::Responsetoo early, and Rails warns.Rails 8.1.4 added an
:action_controller_liveload hook. This PR prepends the reporter from that hook, so nothing touchesActionController::Liveuntil 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 leavesActionController::Liveunloaded. The second example fails on master and passes here.spec/isolatedandspec/sentrypass on theruby-3.4_rails-8.1.3cell; RuboCop is clean on both files.