summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrey Andreev <narf@devilix.net>2019-03-16 01:02:39 +0100
committerAndrey Andreev <narf@devilix.net>2019-03-16 01:03:19 +0100
commit48c5af1ac56c6b4bf7f4c12dc585561285fad83f (patch)
treeb6f1b9976635b022d8a43c07b86331b71c92fc1d
parent2ba349a9018ba0eeb7529e2012554cb84627bed5 (diff)
[ci skip] Merge pull request #5708 from mchobbylong/develop
Resolve race condition in redis driven session key get_lock
-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 434b11e58..25bf80706 100644
--- a/system/libraries/Session/drivers/Session_redis_driver.php
+++ b/system/libraries/Session/drivers/Session_redis_driver.php
@@ -359,11 +359,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;