Revolution: There was an error retrieving or creating session id

Created on 7 Aug 2020  Â·  5Comments  Â·  Source: modxcms/revolution

Bug report

Summary

Unnecessary "error" log message produced whenever a new session is created (including for anonymous users).

Step to reproduce

  1. Ensure that MODX "Logging Level" (log_level) is set to at least a value of 3 (modX::LOG_LEVEL_INFO).
  2. Open a new browser window that has not accessed the MODX site (a new incognito mode window works well).
  3. Navigate to the MODX site.
  4. Check the error log file for the site.

Observed behavior

A message stating (in part) "There was an error retrieving or creating session id" will be in the log file with a session ID.

Expected behavior

No log message should be created.

Related issue(s)/PR(s)

Likely-related bug report: #10631
Discussion of issue: https://forums.modx.com/thread/95437/revo-error-there-was-an-error-retrieving-or-creating-session-id

Environment

Affects all versions of MODX Revolution (so far as I can tell). Many MODX versions have exhibited this behavior over at least the past 3 years, running on several versions of Apache and MySQL and running on both Linux and Windows.

bug

All 5 comments

Given that only shows when you deliberately lower the log level to show
info messages, is this really an issue?

Op vr 7 aug. 2020 21:56 schreef CarlBohman notifications@github.com:

Bug report Summary

Unnecessary "error" log message produced whenever a new session is created
(including for anonymous users).
Step to reproduce

  1. Ensure that MODX "Logging Level" (log_level) is set to at least a
    value of 3 (modX::LOG_LEVEL_INFO).
  2. Open a new browser window that has not accessed the MODX site (a
    new incognito mode window works well).
  3. Navigate to the MODX site.
  4. Check the error log file for the site.

Observed behavior

A message stating (in part) "There was an error retrieving or creating
session id" will be in the log file with a session ID.
Expected behavior

No log message should be created.
Related issue(s)/PR(s)

Likely-related bug report: #10631
https://github.com/modxcms/revolution/issues/10631
Discussion of issue:
https://forums.modx.com/thread/95437/revo-error-there-was-an-error-retrieving-or-creating-session-id
Environment

Affects all versions of MODX Revolution (so far as I can tell). Many MODX
versions have exhibited this behavior over at least the past 3 years,
running on several versions of Apache and MySQL and running on both Linux
and Windows.

—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
https://github.com/modxcms/revolution/issues/15188, or unsubscribe
https://github.com/notifications/unsubscribe-auth/AACMM4CMEIAW743AHYD7MN3R7RMATANCNFSM4PX6KTLA
.

I did a stack trace to figure out what was happening. This is what I saw (with ... being substituted for my actual path):

#0 ...\core\model\modx\modsessionhandler.class.php(90): modSessionHandler->_getSession('e5b6bdb25ef869c...')
#1 [internal function]: modSessionHandler->read('e5b6bdb25ef869c...')
#2 ...\core\model\modx\modx.class.php(2351): session_start()
#3 ...\core\model\modx\modx.class.php(2593): modX->startSession()
#4 ...\core\model\modx\modx.class.php(558): modX->_initSession(NULL)
#5 ...\htdocs\index.php(50): modX->initialize('web')
#6 {main}

After visual code inspection and debugging, it is clear that the message is being reported when the session is being initialized for the first time (such as when an anonymous user access the site for the first time). The _getSession() function is unable to find the session because it doesn't exist yet and it has not been told to create it in this particular stack trace. So it creates an unneeded log message instead.

One possible way to address this is to make a change to _getSession similar to the following:

    protected function _getSession($id, $autoCreate= false) {
        $this->session= $this->modx->getObject('modSession', array('id' => $id), $this->cacheLifetime);
        if ($autoCreate && !is_object($this->session)) {
            $this->session= $this->modx->newObject('modSession');
            $this->session->set('id', $id);
        }
        if (!($this->session instanceof modSession) || $id != $this->session->get('id') || !$this->session->validate()) {
            if ($this->modx->getSessionState() == modX::SESSION_STATE_INITIALIZED) {
                $this->modx->log(modX::LOG_LEVEL_INFO, 'There was an error retrieving or creating session id: ' . $id);
            }
        }
        return $this->session;
    }

The only change I made was to wrap the call to $this->modx->log() in an additional check to see if the session is initialized or not. If the session is not yet initialized, the message doesn't appear to add any value.

EDIT: I realized that I still had some of my debug code in the _getSession() function above, so I removed it.

If it's a nuisance message that has no value (given that it is an expected condition, but being reported with the word "error") and multiple people have been complaining about it over the span of years, then I do think it's a valid issue.

Given that this issue is at least 10 years old, and I sought insight into it 3 years ago (in the thread Carl referenced), it would be nice to fix this, as it creates unnecessary noise in the logs, making it that much harder to find real issues.

Fixed #15292

@CarlBohman Thanks!

@modxbot close

Was this page helpful?
0 / 5 - 0 ratings