Decreasing the probability of race condition in session lock#5170
Conversation
Signed-off-by: tianhe1986 <w1s2j3229@163.com>
Signed-off-by: tianhe1986 <w1s2j3229@163.com>
|
It is unclear how or why this patch improves anything ... You'll need to elaborate a lot. :) |
|
Take When two requests with same cookie arrive at the same time, the two processes may also execute the code to here simultaneously, and get $ttl = -2. However, |
|
Ok, that makes sense for Redis, although it can be simplified: (yes, What about memcache though? |
|
memecache also could use Although it also has problem, I'll modify the code according to your advice :) |
Signed-off-by: tianhe1986 <w1s2j3229@163.com>
| } | ||
|
|
||
| if ( ! $this->_memcached->set($lock_key, time(), 300)) | ||
| $result = ($this->_memcached->getResultCode() === Memcached::RES_NOTFOUND) |
There was a problem hiding this comment.
With the method params matching ...
$method = ($this->_memcached->getResultCode() === Memcached::RES_NOTFOUND) ? 'add' : 'set';
if ( ! $this->_memcached->$method($lock_key, time(), 300))
| $result = ($ttl === -2) | ||
| ? $this->_redis->set($lock_key, time(), array('nx', 'ex' => 300)) | ||
| : $this->_redis->setex($lock_key, 300, time()); | ||
| if ( ! $result) |
There was a problem hiding this comment.
Needs a single empty line prior to this.
Signed-off-by: tianhe1986 <w1s2j3229@163.com>
…ce_condition Decreasing the probability of race condition in session lock

When using
redisormemcachedsession driver, if a web-client perform multiple requests at the same time, two or more requests may get the session lock, and finally some of them would generate "Session: Error while trying to free lock for" error log.Using
Redis::setnxandMemcached::addproperly could help to decrease the probability of this race condition.