#32330 [Opn->Fbk]: session_destroy, "Failed to initialize storage module", custom session handler

From: Date: Thu, 17 Mar 2005 08:43:47 +0000
Subject: #32330 [Opn->Fbk]: session_destroy, "Failed to initialize storage module", custom session handler
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-75417@lists.php.net to get a copy of this message
 ID:          32330
 Updated by:  sniper@php.net
 Reported By: mfischer@php.net
-Status:      Open
+Status:      Feedback
 Bug Type:    Session related
 PHP Version: 4.3.10
 New Comment:

Please try using this CVS snapshot:

  http://snaps.php.net/php4-STABLE-latest.tar.gz
 
For Windows:
 
  http://snaps.php.net/win32/php4-win32-STABLE-latest.zip




Previous Comments:
------------------------------------------------------------------------

[2005-03-16 09:29:18] mfischer@php.net

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 this bug report at http://bugs.php.net/?id=32330&edit=1


Thread (38 messages)

« previous php.bugs (#75417) next »