From 26678d8ea3f05b5508c0ebc80cb2bc40e0a66556 Mon Sep 17 00:00:00 2001 From: Patricio Cano <suprnova32@gmail.com> Date: Thu, 29 Sep 2016 08:18:15 -0500 Subject: [PATCH] Fix race condition that can be triggered if the token expires right after we retrieve it, but before we can set the new expiry time. --- lib/gitlab/lfs_token.rb | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/lib/gitlab/lfs_token.rb b/lib/gitlab/lfs_token.rb index 7b3bbcf6a32..5f67e97fa2a 100644 --- a/lib/gitlab/lfs_token.rb +++ b/lib/gitlab/lfs_token.rb @@ -20,13 +20,8 @@ module Gitlab def token Gitlab::Redis.with do |redis| token = redis.get(redis_key) - - if token - redis.expire(redis_key, EXPIRY_TIME) - else - token = Devise.friendly_token(TOKEN_LENGTH) - redis.set(redis_key, token, ex: EXPIRY_TIME) - end + token ||= Devise.friendly_token(TOKEN_LENGTH) + redis.set(redis_key, token, ex: EXPIRY_TIME) token end -- GitLab