php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #58802 memcache.lock_timeout unexpected behaviour of session handler
Submitted: 2009-08-13 05:48 UTC Modified: -
Votes:12
Avg. Score:5.0 ± 0.0
Reproduced:12 of 12 (100.0%)
Same Version:1 (8.3%)
Same OS:1 (8.3%)
From: stan at absite dot com Assigned:
Status: Open Package: memcache (PECL)
PHP Version: 5.2.0 OS: Debian etch
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2009-08-13 05:48 UTC] stan at absite dot com
Description:
------------
this is bug report for beta 3.0.4
session locking does appear to timeout randomly.
Can't find much info about memcache.lock_timeout so if this is not intended for what I think please correct me.

directive memcache.lock_timeout (tried to set in php using ini_set() also tried to set in php.ini) is in seconds I assume. Default is 15s. Script is waiting random time to get session if is locked and then breaks the lock. Time is really random but it never takes longer than memcache.lock_timeout. I don't think this is expected. In compare with file session handler session is locked until it has been released by locking thread, so no lock time out at all.

Reproduce code:
---------------
script 1, 
- open session. 
- put the script to sleep for lets say 60 seconds.

script 2.
- open session.
- print 'hello world'.

run script 1 and script2 immediately after script 1.
do it several times and watch the clock. 
Script 2 will print 'hello world' in random time. If you refresh the script 2 after printing out the message and script1 is still running, it will complete immediately, that means lock was broken and released by script2 first run.
Script 2 will print out the line after random time but within 15s if default timeout is set.

Expected result:
----------------
I think expected would be script2 to wait at least memcache.lock_timeout seconds to break the lock of the session.
0 option would be great to simulate infinite timeout.

Actual result:
--------------
Script 2 breaks the session lock at random time but within memcache.lock_timeout seconds 

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-03-03 08:18 UTC] s dot de dot vathaire at neov dot net
Me too !
Same issue.
Tried setting memcache.lock_timeout to 60 but Script 2 breaks the session lock at random time but within
memcache.lock_timeout seconds

PHP Version 5.2.6-1+lenny3
Memcache
Version 	3.0.4
Revision 	$Revision: 1.83.2.36 $
 [2011-07-03 23:33 UTC] annon at annonmail dot com
Version 	3.0.6
Revision 	$Revision: 310129 $ 

This is occurring for me also. It was causing page loads to take 15s+. Setting memcache.lock_timeout to 1 seems to help (but not fix). I am lucky enough to be able to not use sessions for the time being.
 [2011-12-05 11:52 UTC] mvfreelancer at gmail dot com
Same problem here.
CentOS6 - 2.6.32-71.29.1.el6.centos.plus.x86_64
memcached 1.4.7
PHP 5.3.2

my php -i output

memcache
memcache support => enabled
Version => 3.0.6
Revision => $Revision: 310129 $

Directive => Local Value => Master Value
memcache.allow_failover => 1 => 1
memcache.chunk_size => 32768 => 32768
memcache.compress_threshold => 20000 => 20000
memcache.default_port => 11211 => 11211
memcache.hash_function => crc32 => crc32
memcache.hash_strategy => consistent => consistent
memcache.lock_timeout => 1 => 1
memcache.max_failover_attempts => 20 => 20
memcache.protocol => ascii => ascii
memcache.redundancy => 1 => 1
memcache.session_redundancy => 1 => 1


session
Session Support => enabled
Registered save handlers => files user memcache
Registered serializer handlers => php php_binary wddx

Directive => Local Value => Master Value
session.auto_start => Off => Off
session.bug_compat_42 => Off => Off
session.bug_compat_warn => Off => Off
session.cache_expire => 180 => 180
session.cache_limiter => nocache => nocache
session.cookie_domain => no value => no value
session.cookie_httponly => On => On
session.cookie_lifetime => 0 => 0
session.cookie_path => / => /
session.cookie_secure => Off => Off
session.entropy_file => no value => no value
session.entropy_length => 0 => 0
session.gc_divisor => 1000 => 1000
session.gc_maxlifetime => 1440 => 1440
session.gc_probability => 1 => 1
session.hash_bits_per_character => 5 => 5
session.hash_function => 0 => 0
session.name => PHPSESSID => PHPSESSID
session.referer_check => no value => no value
session.save_handler => memcache => memcache
session.save_path => tcp://127.0.0.1:11211?
persistent=1&weight=1&timeout=1&retry_interval=15 => tcp://127.0.0.1:11211?
persistent=1&weight=1&timeout=1&retry_interval=15
session.serialize_handler => php => php
session.use_cookies => On => On
session.use_only_cookies => On => On
session.use_trans_sid => 0 => 0

----
How to reproduce:
A) create two php script files with the contents as below
B) open your browser of choice and try load both scripts as fast as you can - 
say within 3 seconds from one another

Expected Results
- the first script should run in less than 11 secs (sleep 10 + few microseconds 
of processing) and _SESSION[count]=0
- the first script should run in less than 11 secs (sleep 10 + few microseconds 
of processing) and _SESSION[count]=1

Actual Results
- the first script should run in less than 11 secs (sleep 10 + few microseconds 
of processing) and _SESSION[count]=0
- the first script should run in less than 21 secs (sleep 10 of the first script 
+ sleep 10 secs of this script + few microseconds of processing) and 
_SESSION[count]=0 (note the session count was not incremented)


<?php
$a = microtime(true);
session_start();
if(!isset($_SESSION['count'])) {
        $_SESSION['count'] = 0;
}
else {
        $_SESSION['count'] = $_SESSION['count'] + 1;
}
sleep(10);

print_r($_SESSION);
print_r($_SERVER);

echo PHP_EOL."end";
echo PHP_EOL.(microtime(true)-$a);

?>
 
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Mon Jun 24 15:01:26 2019 UTC