Information Required ? Pending

User tests: Successful: Unsuccessful:

avatar Denitz
Denitz
17 Nov 2020

Pull Request for Issue #30225 .

Summary of Changes

If the session handler is database, Joomla\CMS\Session\MetadataManager::checkSessionRecordExists() performs an extra database query which is is useless because if we have active session at this stage, it means that the data was loaded from #__session table before and the session record exists.

We can check the session presence for:

  1. Non-database handler.
  2. Inactive session.
  3. New session (calling isNew() method results in getting session data, which also results in auto-writing the session record in the database for the new record, next it's updated via updateSessionRecord() ).

Testing Instructions

Use database session handler, load page multiple times, see that we always have 3rd query:

SELECT `session_id`
FROM `jos_session`
WHERE `session_id` = :session_id LIMIT 1

which is executed right after:

SELECT `data`
FROM `jos_session`
WHERE `session_id` = ?

Actual result BEFORE applying this Pull Request

The 3rd query always exists.

Expected result AFTER applying this Pull Request

The 3rd query from above is only executed once on a new session. You can test the new session creation and expiration by truncating the #__session table, or deleting cookies, or setting past time in #__session table.

Documentation Changes Required

No.

avatar Denitz Denitz - open - 17 Nov 2020
avatar Denitz Denitz - change - 17 Nov 2020
Status New Pending
avatar joomla-cms-bot joomla-cms-bot - change - 17 Nov 2020
Category Libraries
avatar ceford ceford - test_item - 18 Nov 2020 - Tested successfully
avatar ceford
ceford - comment - 18 Nov 2020

I have tested this item successfully on e1c1eac

Confirm: on second page load the SELECT session_id query is not present.


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/31421.

avatar jwaisner jwaisner - test_item - 24 Nov 2020 - Tested successfully
avatar jwaisner
jwaisner - comment - 24 Nov 2020

I have tested this item successfully on e1c1eac


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/31421.

avatar jwaisner jwaisner - change - 24 Nov 2020
Status Pending Ready to Commit
avatar jwaisner
jwaisner - comment - 24 Nov 2020

RTC


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/31421.

avatar Fedik
Fedik - comment - 24 Nov 2020

I think this need to be reviewed by someone experienced

avatar jfeedback
jfeedback - comment - 25 Nov 2020

This might look like a duplicate query, but from an engineering perspective, the current API is correct and a system engineer from the Joomla team should reject this pull request.

The changes in this pull request introduce a hidden dependency for this metadata manager class to function properly, the assumption that the session handler has promptly written a record to the database before this metadata manager can be properly used. This is the type of assumption that leads to broken code.

For background, the database session handler in Joomla 3 and earlier have this same fundamental problem in that it assumes that it can only perform UPDATE queries, which means it relies on another part of the system to run the INSERT query and if that doesn't happen for some reason then the session handler will critically fail. Luckily, someone fixed this fatal flaw in the 4.0 API.

avatar Quy Quy - change - 25 Nov 2020
Status Ready to Commit Pending
avatar Fedik
Fedik - comment - 26 Nov 2020

@wilsonge please review

avatar Denitz
Denitz - comment - 26 Nov 2020

@jfeedback The session is always started before the metadata manager runs the code (because the session ID is used by the manager), hence the data is written.
And 4.0 database session storage does INSERT in write(), am I wrong?

avatar wilsonge
wilsonge - comment - 28 Nov 2020

The comment from @jfeedback is correct from an architectural perspective. Honestly 99% of the time this code probably is fine - but there are going to be edge cases where you can get issues happening

avatar wilsonge wilsonge - close - 28 Nov 2020
avatar wilsonge wilsonge - change - 28 Nov 2020
Status Pending Closed
Closed_Date 0000-00-00 00:00:00 2020-11-28 13:01:31
Closed_By wilsonge
Labels Added: Information Required ?

Add a Comment

Login with GitHub to post a comment