Ticket #648 (closed Bug: fixed)

Opened 5 months ago

Last modified 4 months ago

Workaround request for PHP bug 32330

Reported by: edam Owned by: Shadowhand
Priority: major Milestone:
Component: Libraries:Session Version: SVN HEAD
Keywords: Cc:

Description

PHP has a bug: http://bugs.php.net/bug.php?id=32330

which prevents Kohana's Session::create() from working on affected systems. A combination of custom session handlers and recreating the session causes PHP to throw an error. The bug is present up to PHP 5.2.5 but is apparently now fixed in CVS.

Here is the error I get:

Fatal error: session_start() [<a href='function.session-start'>function.session-start</a>]: Failed to initialize storage module: user (path: /var/lib/php5) in /home/XXXXXXX/system/libraries/Session.php on line 180

A workaround for the bug is to re-set the session save handle in between session_destroy() and session_start(). I can confirm this works. The following code added to Session.php at line 165, in Session::create() after the call to $this->destroy(), resolves the issue:

		// Re-register non-native driver as the session handler to work
		// around PHP bug #32330
		if (self::$config['driver'] != 'native')
		{
			session_set_save_handler
			(
				array(self::$driver, 'open'),
				array(self::$driver, 'close'),
				array(self::$driver, 'read'),
				array(self::$driver, 'write'),
				array(self::$driver, 'destroy'),
				array(self::$driver, 'gc')
			);
		}

I realise that this means the above code is duplicated as it also appears in __construct(), but this is necessary (I think?). The first time Session::create() is called from Session::__construct(), it calls $this->destroy() which in turn calls session_destroy(). If the custom session save handler weren't also set in __construct(), this call to session_destroy() would invoke PHP's default session handling.

I also realise that this isn't a bug in Kohana. The update from 2.1.1 to 2.1.2, in which the Session::create() code changed, has broken our Kohana app! And I doubt I will be the only person to suffer this although I suspect the lack of a report to date is due to Session::create() not being a common call and the problem only appearing since 2.1.2. I also doubt this would be the first PHP bug that Kohana's had to work around! ;o)

Change History

Changed 5 months ago by Shadowhand

  • owner changed from - No owner - to Shadowhand
  • status changed from new to assigned

Changed 5 months ago by Shadowhand

  • status changed from assigned to closed
  • resolution set to fixed

Fixed in r2852, merged in r2856.

Changed 4 months ago by anonymous

  • milestone deleted

Milestone 2.1.3 deleted

Note: See TracTickets for help on using tickets.