Skip to content
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

Fix unstable session manager #14973

Conversation

elioermini
Copy link
Member

Description

Fix of the unstable behaviour of the session management with high volume of concurrent sessions.

Fixed Issues

  1. Concurrent (quick reload) requests on checkout cause cart to empty - related to session_regenerate_id #12362: Concurrent (quick reload) requests on checkout cause cart to empty - related to session_regenerate_id

Manual testing scenarios

  1. Reach the checkout page with products in the cart
  2. Press CMD+R or ALT+F5 multiple times to refresh the page, after the fix the user is not being logged out and redirected to the empty cart page.

We already deployed the fix on our high traffic website and the issue is fixed.

@miguelbalparda
Copy link
Contributor

There are a couple of fixes referenced in #12362, some also for 2.2. Have you seen those?

@elioermini
Copy link
Member Author

Hi @miguelbalparda not yet, I'll have a deeper look next week. Thanks.

@VladimirZaets
Copy link
Contributor

Hi @elioermini , thank you for collaboration.

@magento-engcom-team
Copy link
Contributor

@elioermini thank you for contributing. Please accept Community Contributors team invitation here to gain extended permissions for this repository.

@acetronaut
Copy link

Hi @elioermini & @magento-engcom-team

@elioermini Did you make any changes / enhancements in this pull request on the code that i wrote here? #12362

There have been reports i can see of a possible issue with http to https, although i think people should ideally have sitewide SSL, i think it will need some testing to ensure there is no issue here.

@magento-engcom-team - I wrote this code back in november. I have also got this deployed on several high turnover sites - both CE and EE versions and this seems to be running for us with no issue. Clients are no longer complaining - and we have done some extensive hotjar sessions where we can see this issue no longer present for customers, as well as it increasing conversion / reducing dropouts, especially on mobile

One thing i am interested to know though - is we are nearly 6 months after this issue. I can see this issue present on some EE websites online now, i am curious to why there seems to have been lack of acknowlegement on the scale of the issue, and also why the issue seems to have been added to your milestone and then subsequently removed.

Further to this

public function regenerateId() was updated in 2.1.9 and most likely the reason this isnt apparent on all M2 instances

https://github.com/magento/magento2/blob/2.1.8/lib/internal/Magento/Framework/Session/SessionManager.php

https://github.com/magento/magento2/blob/2.1.9/lib/internal/Magento/Framework/Session/SessionManager.php

So a revert to the previous code may resolve the issue - however possibly re-introduce a different bug this was changing anyway. Could you let me know and give me a test case please for what issue you were trying to solve with this update which introduced this issue and why you chose not to roll it back.

The change you made in 2.1.9 was probably for a reason, and if you have a example of a problem the change you made was solving - i would advise that this pull request also needs retesting against this.

Also have noticed some changes a while ago and attempts to make changes, as well as closing some other tickets off in favour of a "Magento Solution" so i am curious whether you can give the magento take on this issue and what has been looked into?

It took me 2 solid (and very long) days to write and test this and i am sure you have some very clever people in there that you could assign this to who should be able to look at this in full and also in respect to scenarios that i wont have tested (for example http to https as all of our clients are now 100% SSL).

As soon as i became aware of this issue it became a showstopper / top priority for us due to its nature of affecting sales. I was hoping to see some progress from your team by now on the issue. Maybe there has been, and if there has could you please make this public.

I hope you decide to engage a little more on the issue with some technical / developer feedback from the changes i made at least. im sure if you had have done this already a lot of clever people in the community could have helped chip in to solve this issue with you

I look forward to your reply @magento-engcom-team

@aeu
Copy link

aeu commented May 4, 2018

Subscribed

@elioermini
Copy link
Member Author

Hi @acetronaut yes that's basically the code you added in the comment plus this line to renew the cookie https://github.com/elioermini/magento2/blob/6ee737bb43adcd9b40c170170c5ea8e5d5ad6731/lib/internal/Magento/Framework/Session/SessionManager.php#L201

Thanks a lot for your contribution, it appears to be close to what is being suggested on php.net http://php.net/manual/en/function.session-regenerate-id.php.
It's working very well on our side.
I'm not sure how to solve the issue of the CI at the moment. Looks like it doesn't like the php_ini directive. It would be nice a hint from the core team.

@piotrekkaminski
Copy link
Contributor

Recent internal PR https://github.com/magento/magento2ce/pull/2496 resolves the issues for https only by removing regenerate but this PR should resolve it for mixed mode (http/https) when regenerate is still security best practice.

@ishakhsuvarov
Copy link
Contributor

ishakhsuvarov commented May 10, 2018

Hi @elioermini @acetronaut @piotrekkaminski

Similar to provided in this Pull Request fix has been evaluated by the core team when investigating this issue. Unfortunately, in some scenarios, specifically when using Redis for session storage it may cause significant performance degradation on some scenarios. @elioermini Have you tried this commit with Redis session storage?

Current solution, which is already available in 2.2-develop branch a6f146c is to eliminate session regeneration for stores using full https mode.

We are going to check the specific solution provided in this Pull Request with possible redis issues in mind and let you know the result.

Thank you for collaboration.

/**
* Session destroyed threshold in seconds
*/
const SESSION_DESTROYED_THRESHOLD = 300;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please, remove constant and use session lifetime value from the system configuration

@@ -501,7 +516,29 @@ public function regenerateId()
return $this;
}

$this->isSessionExists() ? session_regenerate_id(true) : session_start();
// @codingStandardsIgnoreStart
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why was this code fragment suppressed?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It has been replaced with the if / else block till line 540

$sid = $this->sidResolver->getSid($this);
// potential custom logic for session id (ex. switching between hosts)
$this->setSessionId($sid);
session_start();
if (isset($_SESSION['destroyed'])) {
if ($_SESSION['destroyed'] < time() - self::SESSION_DESTROYED_THRESHOLD) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Combine this expression with previous if statement

@sidolov sidolov self-assigned this May 11, 2018
@aeu
Copy link

aeu commented May 12, 2018

@acetronaut That was a really good find on the change to regenerateId(), and I agree with you, that this is most likely the change that broke it.

@sidolov
Copy link
Contributor

sidolov commented May 25, 2018

@elioermini , any updates?

@okorshenko okorshenko removed this from the May 2018 milestone May 31, 2018
@ishakhsuvarov ishakhsuvarov removed their assignment Jul 12, 2018
@sidolov sidolov removed the request for review from larsroettig August 8, 2018 09:49
@magento-cicd2
Copy link
Contributor

magento-cicd2 commented Aug 8, 2018

CLA assistant check
All committers have signed the CLA.

@sidolov
Copy link
Contributor

sidolov commented Aug 8, 2018

Hi @elioermini , I fixed minor issues. Please, sign CLA, otherwise, we can't process your pull request

@elioermini
Copy link
Member Author

Sorry the delay I got side-tracked, can someone help me making the hardcoded values configurable? Thanks

@sidolov
Copy link
Contributor

sidolov commented Aug 9, 2018

@elioermini , I think we are done with all the requested changes. The solution looks good to me

@magento-engcom-team
Copy link
Contributor

Hi @sidolov, thank you for the review.
ENGCOM-1440 has been created to process this Pull Request

@magento-engcom-team
Copy link
Contributor

Hi @elioermini. Thank you for your contribution.
We will aim to release these changes as part of 2.2.7.
Please check the release notes for final confirmation.

Please, consider to port this solution to 2.3 release line.
You may use Porting tool to port commits automatically.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.