diff options
author | Andrey Andreev <narf@devilix.net> | 2019-03-16 01:02:39 +0100 |
---|---|---|
committer | Andrey Andreev <narf@devilix.net> | 2019-03-16 01:03:19 +0100 |
commit | 48c5af1ac56c6b4bf7f4c12dc585561285fad83f (patch) | |
tree | b6f1b9976635b022d8a43c07b86331b71c92fc1d /system/libraries | |
parent | 2ba349a9018ba0eeb7529e2012554cb84627bed5 (diff) |
[ci skip] Merge pull request #5708 from mchobbylong/develop
Resolve race condition in redis driven session key get_lock
Diffstat (limited to 'system/libraries')
-rw-r--r-- | system/libraries/Session/drivers/Session_redis_driver.php | 12 |
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; |