-
Notifications
You must be signed in to change notification settings - Fork 326
Session lock record with PHP 7.0.9 #269
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Session settings have changed quite a bit for php 7 version of the extension, you will probably need to tweak your settings a bit to get it to behave as it did in PHP 5.6 |
Please state the version of php-memcached that you are using (or the git revision if you're building from source). |
I tried to use repository and build php7 source branch, but in both case i have the same problem. The versions is as follows: From repository From php7 branch: |
I had same problem and I resolved the issue by disabling |
Hey guys, You can set memcached.sess_lock_expire to your max_execution_time value to avoid that bug from #266. This way the extension won't fall back to the max_execution_time value - which it reads incorrectly. |
I disabled |
In the case you describe, the error is normal.
So this is another problem, and is not actually an issue cause by this extension. The issue #266 consists in the session lock being permanently set (with 0 TTL) so you reach the timeout limit on any request - and the lock is not removed even after the timeout, when the request is processed. |
My problem is with parallel requests. If I have an ajax request running and I send another request, both requests are stopped and receive 500 with error from first post. |
I have the same issue, i run a lot of paralell requests and i have repeating "Unable to clear session lock record" fatals. I disabled lazy write and tried following memcached config: memcached.sess_lock_expire 7200 with: With older versions on php 5.4 base i have absolutely no issues. It gives me a feeling that on PHP7 they are processed much faster and due to this fact create more blocking requests. One question: Is this issue fixed to PHP 7.0.9, so a up or downgrade could help? |
Confirming here in php 7.0.12 if you set a fixed value for memcached.sess_lock_expire the issue goes away. |
Please read up on how these values are consumed: https://github.com/php-memcached-dev/php-memcached/blob/master/memcached.ini Increasing Can anyone see why the solution wouldn't be to simply increase Eg. Where default |
For our Moodle site, we use memcached for PHP sessions. Because of the way Moodle uses the session handler in its AJAX calls (several issued before main page request finishes) we often get blocked session_start() calls. See this bug and this bug for details. To get the new version to behave like the old one, we set the lock_wait_min and _max to the same reduced value of 150. This makes the spin lock retry 150 msec, as was the default in 2.2.x. Moodle config default is to wait a max of 120 secs to attain a session lock, so we set the retry count to 800 (120 / .15). One or two seconds seems to be much to long to wait between attempts; much better to make several frequent attempts waiting (sleeping) only 150 msec at a time. |
I've read through this ticket and I'm not sure what problem or change request is still outstanding. |
Well somwhow it seems session locking might be broken with php7, similar issue here. |
@andrerom As I wrote, I don't fully understand the specific problem(s?) that people are having in this thread. If the problem(s?) is also affecting you, can you help to explain what would resolve it? |
I believe the session locking problem isn't so much an issue with the php_memcached as it is with PHP (all versions). See https://bugs.php.net/bug.php?id=71962. The messages having to do with failure to clear lock records come about because competing processes using the same session (i.e. main page request, and any number of AJAX calls associated it), are all working with the same memcached item--the first to finish removes the lock item, and the rest all report they were unable to do so simply because it wasn't there any longer. |
I still don't understand if there is something that needs to be fixed or changed or better documented. @woolardfa The bug you linked is specific to the memcached extension, it just happens to be filed in the PHP bug tracker, and I don't see in what way the PHP version affects the bug. |
@sodabrew, you are correct. As I said in previous message, the issue is not in php_memcached. |
With the explanation from woolardfa i could successfully resolve the issue from my application. Thanks! |
Can the ini file description be updated please: https://github.com/php-memcached-dev/php-memcached/blob/master/memcached.ini Section: "memcached.sess_lock_max_wait" is deprecated, i assume that "memcached.sess_lock_wait_max" will be i place but i´d like to know. |
Any update on this? |
Any chance queing requests on the server side can solve this problem? |
If this is an issue regarding only ajax requests, how about http://php.net/manual/en/function.session-write-close.php |
session_write_close will end up clobbering the session data. session_abort() is the way to leave it alone. |
@woolardfa would session_abort() has also work immediatly after session_write_close() in case session data needs update on ajax call? |
No. Use one or the other. The point is that you have to detect whether or not PHP/session/memcached was truly successful in establishing the lock entry (semaphore), and thus acquiring the right to update the session content, OR whether it just gave up after trying the specified number of times (timed out), and returned a True (the bug in session_start()) anyway. In this latter case, the session content given to the usurping process will be empty... and when session_write_close is called, or the page is allowed to end normally, that bogus (empty) session data will be written back clobbering the valid data. Calling session_abort will prevent that. |
I think the problem is with async requests (using a service worker). Only if memcached can handle async requests would it solve the problem or move long processes to the background to make sure sync requests do not get blocked. |
Just an FYI... have tested PHP 7.2 (7.2.6), the underlying issue where session_start returns true when it in fact failed to acquire the session lock, and subsequently corrupts the existing session data, has been fixed. A call to session_start() now returns false when it failed to acquire the session lock. |
Hmmm I'm running |
php 7.2.15, libmemcached version 1.0.18 |
Just an update - I am using AWS Elasticache as my Memcache and PHP 7.1. Setting |
Update. I was able to watch error logs and tweak all these values live and figure out what worked and what did not. Turning off |
php-memcached-dev/php-memcached#269 PHP Warning: session_start(): Unable to clear session lock record.
@csev Good news that you've determined your simplest/best path, and do not want to discourage you, but do want to offer some things to consider if you choose to keep using memcached for sessions. Firstly, I'd recommend getting to a current version of PHP where the fundamental bug is fixed. The bug is not in libmemcached, or in php-memcached; it's in PHP. The issue is not so much how php_memcached is configured (i.e. _min, _max), because like you said, changing how those are configured didn't eliminate the errors--and they weren't meant to, they were just meant to a) mimic the old session acquisition timings, and b) try to reduce the frequency of the errors based on how one particular application, Moodle, was designed. The issue is more about how sessions are handled at the application level, and whether your application code uses PHP's session management on almost every browser request, like Moodle currently does, (page requests, and subsequent AJAX requests), or if it's more selective. Also, does the application code detect whether the $_SESSION super global is valid or not (most all the time we take that for granted, and that's the patch I added to Moodle's memcached session startup, until PHP was fixed). So, you're right, going with no session locks will eliminate the errors, because that particular lock/semaphore entry won't be created to begin with, and no attempt will be made to remove it. If you're application will work with no concurrency checks (last to touch it wins), then yeah, that's the ticket. |
@woolardfa - Thanks a ton - My application is Tsugi - an EdTech app like Moodle. It can survive with "eventual consistency" and "last write wins". I am encouraged by your suggestion to move beyond 7.1 - what version of PHP is this fixed in? I am a little gun shy as, the road through and to 7.0 and 7.1 was kind of rocky, stuff was not getting fixed, and even the apt repos were wonky and non-standard. So when I got something working I just breathed a sigh of relief and froze my infrastructure. But that was a year ago and I am sure things are better so I am heartened to give it another go if I know what version to go to - I am nervous about jumping to the absolute latest. Again, thanks. |
Nobody has been doing this in this issue, but I think in order to get the full picture of a problem report you should add at least all the settings I mentioned in my comment above: #269 (comment) sess_lock_wait_min, sess_lock_wait_max, sess_lock_expire, sess_lock_retries. Note that the _min and _max times are basically irrelevant for the functioning of the session in general, they are being used to fine-tune timing behavior. The most important settings are lock_expire (also compared to your max_execution_time) and lock_retries. With these set the wrong way, you may end up overwriting your session unintentionally. |
@csev The pain points in Moodle (all handled by moodlehq) were mostly in the 5.x -> 7.x migration. I imagine there ought to be very few going from 7.1 -> 7.3. We've tried to keep our sites fairly up-to-date, and didn't see any issues when we moved from 7.1.x. to 7.2.x. I believe the bug was fixed in 7.2.6 onward, so the current stable of either 7.2 or 7.3 will be prudent... but then, like I said earlier, it will just mean that your application code can then correctly detect whether the session (lock) was acquired or not before it proceeds. |
@woolardfa I upgraded to 7.3 and everything is working fine and I am using the default settings and seeing no lock issues. Thanks for your advice. |
I'm using php 7.3 and it's still a problem. |
I'm using php 7.3 and it's still a problem. However, as discussed above, turning off locking is dependent upon how you use your session data. I think most of my usage should be fine, I guess the next few days will be telling. |
Hello everyone. I have read carefully all the comments and solutions proposed: starting with Frankly, I'm strongly convinced, the issue is not PHP-related, while specific to this extension. Details are the following:
Everything works as it should. So, either default settings for |
I still dont think this is resolved. I had to fall back to using files for sessions |
Hello, I also have this problem with PHP version 7.4.33 and memcached 1.6.19 . |
Same here, still getting this issue with 7.4.33 |
I'm using a Memcached session handler normally in PHP 5.6. But with PHP 7 session don't retrieved properly and the follow warning message was triggered in PHP error log: PHP Warning: session_start(): Unable to clear session lock record.
Any suggestion?
The text was updated successfully, but these errors were encountered: