Avoid the problem that session cannot be acquired when canary release when upgrading from Rails 4.2.x to 5.0.x

Introduction

--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.

Solution

--Fix the rack gem version to 2.0.7

In a word the cause

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

Description

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

Avoid the problem that session cannot be acquired when canary release when upgrading from Rails 4.2.x to 5.0.x
How to solve the problem that notification cannot be requested on iOS14
Solution for errors that occur when upgrading to Rails 5.2 series
[Rails] Solving the problem that session timeout does not work
Rails tutorial When rails new cannot be done due to different versions
Lenovo ThinkPad T14 Gen1 How to solve the problem that the speaker becomes dummy and cannot be used when installing Ubuntu 20.04 on AMD
A story that addresses the problem that REMOTE_ADDR cannot be acquired in a cluster built with Docker Swarm + Traefik (1.7).
[Rails] How to solve the problem that the default image is overwritten when editing without uploading the image [Active Storage]
What to do when the error "Non-static variable x cannot be referenced from static context" in Java. Lessons from the very first step in programming Remarks 01
Strict_loading function to suppress the occurrence of N + 1 problem added from rails 6.1
[Rails] "pry-rails" that can be used when saving with the create method
767 JSON :: ParserError occurs and the problem that the local server cannot be started
The problem that the localhost page launched by Docker cannot be confirmed in the browser when the ESET firewall is operating
[Rails] Rails new cannot be done from Docker
[Rails] Posts cannot be deleted when commented! ??
[Swift5] Problem that Cell cannot be tapped when TextView is placed in TableViewCell
Solves the problem that SwiftPM cannot cross the proxy and cannot add packages to the project
[Rails] What to do when you want to generate an error that cannot be destory when foreign key restrictions are applied