Occasionally breaking changes cause ActionDispatch::Session::SessionRestoreError exceptions. It would be great to be able to do something like this to automatically clear invalid sessions:
class ApplicationController < ActionController::Base
rescue_from ActionDispatch::Session::SessionRestoreError do |exception|
reset_session
redirect_to :home
end
end
This doesn’t work — I’m assuming because the exception is happening at the lower ActionDispatch layer. Is there a way to recover from these errors?
It can. The robust solution is following:
config/initializers/secret_token.rbYourApp::Application.config.secret_token, e.g. by replacing the last char to something elseI know it doesn’t directly solve the problem in question and automating it is relatively hard and not a very good idea (autorewriting app config), but it could be an (expensive) option.
I experienced it with large chunks being written to a session so you can also make sure to check your session against any extensive data storage and swop it to the database.