fix failed login workflow with Redis::Distributed

need to run the pipeline against a singular node

Change-Id: I33befbf4e11daaf5942c37af9233d8f90adde732
Reviewed-on: https://gerrit.instructure.com/c/canvas-lms/+/331124
Reviewed-by: August Thornton <august@instructure.com>
QA-Review: Cody Cutrer <cody@instructure.com>
Product-Review: Cody Cutrer <cody@instructure.com>
Tested-by: Service Cloud Jenkins <svc.cloudjenkins@instructure.com>
This commit is contained in:
Cody Cutrer 2023-10-24 10:43:02 -06:00
parent 385b70c6c5
commit 6f8e97178e
2 changed files with 8 additions and 1 deletions

View File

@ -135,6 +135,11 @@ module CanvasCache
def_failsafe_method(Distributed, m)
end
# not command methods, so skipped by the above loop
# pipelined isn't technically allowed against Distributed,
# but we define this anyway so that we get a proper error
# about it not being supported, instead of an argument error
def_failsafe_method(Distributed, :pipelined)
::Redis::Scripting::Module.prepend(Scripting::Module) if defined?(::Redis::Scripting::Module)
::Redis.prepend(Redis)

View File

@ -92,7 +92,9 @@ module Canvas::Security
key = login_attempts_key(pseudonym)
exptime = Setting.get("login_attempts_ttl", 5.minutes.to_s).to_i
Canvas.redis.pipelined(failsafe: nil) do |pipeline|
node = Canvas.redis
node = node.node_for(key) if node.respond_to?(:node_for)
node.pipelined(failsafe: nil) do |pipeline|
pipeline.hset(key, "unique_id", pseudonym.unique_id)
pipeline.hincrby(key, "total", 1)
pipeline.hincrby(key, ip, 1) if ip.present?