--Canary release is a deployment method that releases a new version of an application to only a part of multiple servers. --Avoid releasing a canary when upgrading from Rails 4.2.x to 5.0.x, that is, creating an environment where Rails 4.2.x and 5.0.x applications are mixed will cause a problem that session cannot be acquired. Want to
I'm not sure if anyone will upgrade to Rails 5.0.x (and with a canary release) at this time, but I hope it helps someone: pray:
Since the content is for those who have some experience with Ruby and Rails, I will omit the basic explanations such as session and rack in Rails.
--Fix the rack gem version to 2.0.7
Caused by the Rails 4.2.x-> 5.0.x upgrade dragging the rack gem to update to 2.0.8 or higher. (There is a destructive change in the generation logic of session_id
in rack 2.0.7-> 2.0.8)
See. https://github.com/rack/rack/blob/master/CHANGELOG.md#208---2019-12-08
Lib / rack / session / abstract / in [rack 2.0.7 ... 2.0.8 diff](https://github.com/rack/rack/compare/2.0.7 ...2.0.8) It is very easy to understand if you look around id.rb
, lib / rack / session / memcache.rb
.
--Up to rack 2.0.7, it is stored in the browser cookie _session_id
(named by Rails /middleware/session/abstract_store.rb#L31)) was used as the key for the session store (Redis, Memcached, etc.)
--Since rack 2.0.8, the value of _session_id
as Digest :: SHA256.hexdigest
is used as the key (Code is around here. /2.0.8/lib/rack/session/abstract/id.rb#L15-L39), public_id
is equal to _session_id
)
--Each session store gem has a fallback method called # get_session_with_fallback
([for redis-rack](https://github.com/redis-store/redis-rack/blob/v2. 1.3 / lib / rack / session / redis.rb # L87-L89), For Memcache # L94-L96)) So you can get the session data generated by the old version of rack from the new version of rack, but not the other way around.
From the above, there is no problem if you deploy the new version of rack gem to all servers at once, but in an environment where rack gems of 2.0.7 or less and 2.0.8 or more are mixed on each server (canary release environment), session
Can no longer be obtained.
Recommended Posts