Open tom-kuca opened 2 years ago
Ran into this myself, same line causing the issue with Rails 6.1
.
include ActionController::Live
also present.
Did you find a workaround?
I didn't need most of ActiveStorage::Streaming
, I replaced it with ActionController::DataStreaming
.
- include ActiveStorage::Streaming
+ include ActionController::DataStreaming
I ended up doing this:
require 'action_controller/caching/actions'
# Workaround for known issue
# https://github.com/rails/actionpack-action_caching/issues/83
module ActionController
module Caching
module Actions
class ActionCacheFilter
alias_method :original_around, :around
def around(controller)
original_around(controller) { yield }
rescue ActionDispatch::IllegalStateError => e
Rails.logger.error(
"Silenced ActionPack / IllegalStateError: #{e.message}"
)
end
end
end
end
end
Given a controller
calling
/articles
with an empty cache triggers the error below. The page is rendered and cached correctly despite the error in the log.Expected behavior
The page should be rendered and cached correctly (as it is) and there should not be any error in the log.
Notes
In my case,
ActionController::Live
was included transitively byinclude ActiveStorage::Streaming
.The problem is caused by setting content type at the end of around filter. At that point, the response is already commited if
ActionController::Live
is included.https://github.com/rails/actionpack-action_caching/blob/05c821ec84eb79760e95b0a57ae72919eefb0257/lib/action_controller/caching/actions.rb#L171
The page is still rendered and cached correctly, because it was already submitted before the error is triggered. The error is not present in following requests which hit the cache.
I was able to reproduced it in a blank rails application, with a single controller generated by scaffolding.
Versions