summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPatricio Cano <suprnova32@gmail.com>2016-09-29 08:18:15 -0500
committerPatricio Cano <suprnova32@gmail.com>2016-09-29 10:25:26 -0500
commit26678d8ea3f05b5508c0ebc80cb2bc40e0a66556 (patch)
tree463e42504cd7eb1b963f07090e42dc1c9c06403e
parent33d1f5904ce94cf2295b94aba6099a502be4b852 (diff)
downloadgitlab-ce-lfs-token-race-condition-fix.tar.gz
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.lfs-token-race-condition-fix
-rw-r--r--lib/gitlab/lfs_token.rb9
1 files 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