#32330 [NEW]: session_destroy, "Failed to initialize storage module", custom session handler

From: Date: Wed, 16 Mar 2005 08:29:19 +0000
Subject: #32330 [NEW]: session_destroy, "Failed to initialize storage module", custom session handler
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-75393@lists.php.net to get a copy of this message
From:             mfischer@php.net
Operating system: 
PHP version:      4.3.10
PHP Bug Type:     Session related
Bug description:  session_destroy,  "Failed to initialize storage module", custom session
handler

Description:
------------
When I use custom session handling functions and use the following session
functions in this order:

[...]
session_set_save_handler(...)
[...]
session_start()
[...]
session_destroy()
[...]
session_start()

I get

"Fatal error: session_start(): Failed to initialize storage module: user
(path: /var/lib/php4) in test.php on line 9"

After session_destroy is called, the functions assigned with
session_set_save_handler() do not work anymore and have to be assigned
again.

By calling session_set_save_handler() again after session_destroy() it
will work.

This applies to 4.9.10 and 5.0.3 as well.

I think the cause is in session.c in php_session_destroy:
[...]
    if (PS(mod)->s_destroy(&PS(mod_data), PS(id) TSRMLS_CC) == FAILURE) {
        retval = FAILURE;
        php_error_docref(NULL TSRMLS_CC, E_WARNING, "Session object
destruction failed");
    }

    php_rshutdown_session_globals(TSRMLS_C);
    php_rinit_session_globals(TSRMLS_C);
[...]

First, the user defined destroy-handler is called then
php_rshutdown_session_globals and then php_rinit_session_globals. In
php_rinit_session_globals PS(mod_data) is cleared

static void php_rinit_session_globals(TSRMLS_D)
{
    PS(id) = NULL;
    PS(session_status) = php_session_none;
    PS(mod_data) = NULL;
    PS(http_session_vars) = NULL;
}

which is a struct for the user defined functions.

The current documentation says:
"session_destroy() destroys all of the data associated with the current
session."

But it seems to do more: it also clears any custom set session save
handlers which unexpected.


Reproduce code:
---------------
<?php
	function dummy() { }

	session_set_save_handler('dummy', 'dummy', 'dummy',
'dummy', 'dummy',
'dummy');

	session_start();
	session_destroy();
	# comment in the next line and the test works
	#session_set_save_handler('dummy', 'dummy', 'dummy',
'dummy', 'dummy',
'dummy');
	session_start();
?>


Expected result:
----------------
No fatal error message

Actual result:
--------------
Fatal error: session_start(): Failed to initialize storage module: user

-- 
Edit bug report at http://bugs.php.net/?id=32330&edit=1
-- 
Try a CVS snapshot (php4):   http://bugs.php.net/fix.php?id=32330&r=trysnapshot4
Try a CVS snapshot (php5.0): http://bugs.php.net/fix.php?id=32330&r=trysnapshot50
Try a CVS snapshot (php5.1): http://bugs.php.net/fix.php?id=32330&r=trysnapshot51
Fixed in CVS:                http://bugs.php.net/fix.php?id=32330&r=fixedcvs
Fixed in release:            http://bugs.php.net/fix.php?id=32330&r=alreadyfixed
Need backtrace:              http://bugs.php.net/fix.php?id=32330&r=needtrace
Need Reproduce Script:       http://bugs.php.net/fix.php?id=32330&r=needscript
Try newer version:           http://bugs.php.net/fix.php?id=32330&r=oldversion
Not developer issue:         http://bugs.php.net/fix.php?id=32330&r=support
Expected behavior:           http://bugs.php.net/fix.php?id=32330&r=notwrong
Not enough info:             http://bugs.php.net/fix.php?id=32330&r=notenoughinfo
Submitted twice:             http://bugs.php.net/fix.php?id=32330&r=submittedtwice
register_globals:            http://bugs.php.net/fix.php?id=32330&r=globals
PHP 3 support discontinued:  http://bugs.php.net/fix.php?id=32330&r=php3
Daylight Savings:            http://bugs.php.net/fix.php?id=32330&r=dst
IIS Stability:               http://bugs.php.net/fix.php?id=32330&r=isapi
Install GNU Sed:             http://bugs.php.net/fix.php?id=32330&r=gnused
Floating point limitations:  http://bugs.php.net/fix.php?id=32330&r=float
No Zend Extensions:          http://bugs.php.net/fix.php?id=32330&r=nozend
MySQL Configuration Error:   http://bugs.php.net/fix.php?id=32330&r=mysqlcfg


Thread (38 messages)

« previous php.bugs (#75393) next »