summaryrefslogtreecommitdiffstats
path: root/system
diff options
context:
space:
mode:
authorAndrey Andreev <narf@devilix.net>2019-03-16 01:02:39 +0100
committerGitHub <noreply@github.com>2019-03-16 01:02:39 +0100
commit0fc1510298234c50b6f0142543acee0cdb569daf (patch)
tree6d5836df9cc4685e30a5bfc32374a2d1bc9e4b11 /system
parent9511cf6564dd87ba022c59ffb9a1dcbfe2709a2a (diff)
parent06739bdc05f2fa5fc92db0675ec48f7374ae50cf (diff)
[ci skip] Merge pull request #5708 from mchobbylong/develop
Resolve race condition in redis driven session key get_lock
Diffstat (limited to 'system')
-rw-r--r--system/libraries/Session/drivers/Session_redis_driver.php12
1 files changed, 7 insertions, 5 deletions
diff --git a/system/libraries/Session/drivers/Session_redis_driver.php b/system/libraries/Session/drivers/Session_redis_driver.php
index 07511e555..c90e94bd3 100644
--- a/system/libraries/Session/drivers/Session_redis_driver.php
+++ b/system/libraries/Session/drivers/Session_redis_driver.php
@@ -383,11 +383,13 @@ class CI_Session_redis_driver extends CI_Session_driver implements SessionHandle
continue;
}
- $result = ($ttl === -2)
- ? $this->_redis->set($lock_key, time(), array('nx', 'ex' => 300))
- : $this->_redis->setex($lock_key, 300, time());
-
- if ( ! $result)
+ if ($ttl === -2 && ! $this->_redis->set($lock_key, time(), array('nx', 'ex' => 300)))
+ {
+ // Sleep for 1s to wait for lock releases.
+ sleep(1);
+ continue;
+ }
+ elseif ( ! $this->_redis->setex($lock_key, 300, time()))
{
log_message('error', 'Session: Error while trying to obtain lock for '.$this->_key_prefix.$session_id);
return FALSE;