summaryrefslogtreecommitdiffstats
path: root/system/libraries
diff options
context:
space:
mode:
authortianhe1986 <w1s2j3229@163.com>2017-07-05 11:05:23 +0200
committertianhe1986 <w1s2j3229@163.com>2017-07-05 11:05:23 +0200
commite98c203f81a11cfd82a644381cd50f865384118d (patch)
treee0264e2811a92ae60cb715b8e13a675a4e8b1faf /system/libraries
parent569cf69078de1c8a970ab4259467dfe27b4cdb96 (diff)
Acquiring memcached lock with add() to avoid race conditions.
Signed-off-by: tianhe1986 <w1s2j3229@163.com>
Diffstat (limited to 'system/libraries')
-rw-r--r--system/libraries/Session/drivers/Session_memcached_driver.php8
1 files changed, 6 insertions, 2 deletions
diff --git a/system/libraries/Session/drivers/Session_memcached_driver.php b/system/libraries/Session/drivers/Session_memcached_driver.php
index 2556bf0f7..542f596c9 100644
--- a/system/libraries/Session/drivers/Session_memcached_driver.php
+++ b/system/libraries/Session/drivers/Session_memcached_driver.php
@@ -310,7 +310,7 @@ class CI_Session_memcached_driver extends CI_Session_driver implements SessionHa
if ( ! $this->_memcached->replace($this->_lock_key, time(), 300))
{
return ($this->_memcached->getResultCode() === Memcached::RES_NOTFOUND)
- ? $this->_memcached->set($this->_lock_key, time(), 300)
+ ? $this->_memcached->add($this->_lock_key, time(), 300)
: FALSE;
}
}
@@ -326,7 +326,11 @@ class CI_Session_memcached_driver extends CI_Session_driver implements SessionHa
continue;
}
- if ( ! $this->_memcached->set($lock_key, time(), 300))
+ $set_result = ($this->_memcached->getResultCode() === Memcached::RES_NOTFOUND)
+ ? $this->_memcached->add($lock_key, time(), 300)
+ : $this->_memcached->set($lock_key, time(), 300);
+
+ if ( ! $set_result)
{
log_message('error', 'Session: Error while trying to obtain lock for '.$this->_key_prefix.$session_id);
return FALSE;