diablomedia / zf1-session-savehandler-dbtable

Session_SaveHandler_DbTable Component from ZF1
BSD 3-Clause "New" or "Revised" License
0 stars 2 forks source link

DBHandl #4

Closed rwese closed 5 years ago

rwese commented 5 years ago

This function has a race-condition:

https://github.com/diablomedia/zf1-session-savehandler-dbtable/blob/26e6930b2db324cb5df074a1422603dec2d0ad85/src/Zend/Session/SaveHandler/DbTable.php#L308

        $rows = call_user_func_array(array(&$this, 'find'), $this->_getPrimary($id));
        if (count($rows)) {
            $data[$this->_lifetimeColumn] = $this->_getLifetime($rows->current());
            if ($this->update($data, $this->_getPrimary($id, self::PRIMARY_TYPE_WHERECLAUSE))) {
                $return = true;
            }
        } else {
            $data[$this->_lifetimeColumn] = $this->_lifetime;
            if ($this->insert(array_merge($this->_getPrimary($id, self::PRIMARY_TYPE_ASSOC), $data))) {
                $return = true;
            }
        }

When multiple workers are running and the underlying session, which is checked at Line https://github.com/diablomedia/zf1-session-savehandler-dbtable/blob/26e6930b2db324cb5df074a1422603dec2d0ad85/src/Zend/Session/SaveHandler/DbTable.php#L315 is closed & deleted before it hits the update stmt https://github.com/diablomedia/zf1-session-savehandler-dbtable/blob/26e6930b2db324cb5df074a1422603dec2d0ad85/src/Zend/Session/SaveHandler/DbTable.php#L320 it won't return true and cause a log warning.

NOTICE: PHP message: PHP Warning:  session_write_close(): Failed to write session data using user defined save handler. (session.save_path: /app/application/../data/session) in /app/library/composer/diablomedia/zendframework1-session/src/Zend/Session.php on line 698

I wrongly opened this issue before https://github.com/diablomedia/zf1-session/pull/6

After cleaning some not required session closes the error became rarer but still is easy to reproduce to call a controller which closes the session a couple of times.

I will refactor this to use a Insert/Update statement instead and post a PR.

rwese commented 5 years ago

see https://github.com/diablomedia/zf1-session/pull/7