Magento2: Database sessions pile up

Created on 8 Jan 2020  路  18Comments  路  Source: magento/magento2

Preconditions (*)

Magento 2.2.x & 2.3.x & 2.4-develop

Steps to reproduce (*)

  1. Configure store to save session in DB(edit env.php)
    image
  2. Change Admin Session Lifetime to 60s for example
  3. Flush cache and logout
  4. Login again and check data in DB session table(note the last added data about your session)
  5. Wait 1 minute and click somewhere in admin
  6. Redirect to login page
  7. Login again
  8. Check data again

Expected result (*)

  1. Expired sessions were deleted.

Actual result (*)

  1. Tons of old entries in "sessions" table

Additional information

See also: https://magento.stackexchange.com/questions/300525/is-the-session-table-supposed-to-be-cleaned-up-automatically

Garbage collect is there, but seems to be never called:

https://github.com/magento/magento2/blob/0a1a283cd6a0cf4b98a051867f90150c9490fcec/lib/internal/Magento/Framework/Session/SaveHandler/DbTable.php#L154

shall we make a PR to add this to the core?

FrameworSession Clear Description Confirmed Format is valid Ready for Work P1 done Reported on 2.2.x Reproduced on 2.4.x S1 Dev.Experience

All 18 comments

Hi @amenk. Thank you for your report.
To help us process this issue please make sure that you provided the following information:

  • [ ] Summary of the issue
  • [ ] Information on your environment
  • [ ] Steps to reproduce
  • [ ] Expected and actual results

Please make sure that the issue is reproducible on the vanilla Magento instance following Steps to reproduce. To deploy vanilla Magento instance on our environment, please, add a comment to the issue:

@magento give me 2.4-develop instance - upcoming 2.4.x release

For more details, please, review the Magento Contributor Assistant documentation.

@amenk do you confirm that you were able to reproduce the issue on vanilla Magento instance following steps to reproduce?

  • [ ] yes
  • [ ] no

Hi @engcom-Hotel. Thank you for working on this issue.
In order to make sure that issue has enough information and ready for development, please read and check the following instruction: :point_down:

  • [ ] 1. Verify that issue has all the required information. (Preconditions, Steps to reproduce, Expected result, Actual result).
    DetailsIf the issue has a valid description, the label Issue: Format is valid will be added to the issue automatically. Please, edit issue description if needed, until label Issue: Format is valid appears.
  • [ ] 2. Verify that issue has a meaningful description and provides enough information to reproduce the issue. If the report is valid, add Issue: Clear Description label to the issue by yourself.

  • [ ] 3. Add Component: XXXXX label(s) to the ticket, indicating the components it may be related to.

  • [ ] 4. Verify that the issue is reproducible on 2.4-develop branch

    Details- Add the comment @magento give me 2.4-develop instance to deploy test instance on Magento infrastructure.
    - If the issue is reproducible on 2.4-develop branch, please, add the label Reproduced on 2.4.x.
    - If the issue is not reproducible, add your comment that issue is not reproducible and close the issue and _stop verification process here_!

  • [ ] 5. Add label Issue: Confirmed once verification is complete.

  • [ ] 6. Make sure that automatic system confirms that report has been added to the backlog.

:white_check_mark: Confirmed by @engcom-Hotel
Thank you for verifying the issue. Based on the provided information internal tickets MC-30631 were created

Issue Available: @engcom-Hotel, _You will be automatically unassigned. Contributors/Maintainers can claim this issue to continue. To reclaim and continue work, reassign the ticket to yourself._

@sdzhepa what is the progress of the internal ticket? Can I check that in any way or is it private?

Hello @amenk

I do not see any progress in the internal ticket MC-30631 Jira ticket.
Unfortunately, it still in "Ready for Dev" status

I've noticed that in customer sessions too. I've had two websites in 2.3.1 and the sessions table reached 2.5m entries with none of them being cleared even though they were long past their expiration date.

After running a cleanup sql command to delete all sessions that the expiry timestamp had passed only 27 sessions were left. I think this is really important because the size of the DB increases really fast in popular eshops.

@ioweb-gr which cleanup command did you use? And how long did it run?

Also each and every crawling attempt seems to open a new session - is that normal?

@amenk I think it was pretty straightforward.

I went to https://www.unixtimestamp.com/index.php to get the timestamp for the date before which I wanted to clear the sessions. For example anything that should have expired 15 days ago e.g. 15/5/2020 = 1589500800

I then executed

DELETE FROM `session` where `session_expires` < 1589500800;

But yeah they do pile up really fast. I might have to create a cron job for this at some point.

@mischabraam Thank you the module :)

I just realized that it might be an option to store the sessions in Redis as well ...

Was this fixed? What's the relevant pull request?

@sidolov @sdzhepa @gabrieldagama was this issue fixed?

@ihor-sviziev @ioweb-gr The issue was fixed by internal pull request and it is already merged, please let us know if you still face the issue on 2.4-develop branch.

Thanks.

So this will be in 2.4.2, right?

Correct @amenk

Was this page helpful?
0 / 5 - 0 ratings