We have moved to Github. Please open tickets there.

Opened 18 months ago

Last modified 17 months ago

#4210 reopened Defect

Autoloader breaks in shutdown function?

Reported by: srokap Owned by:
Priority: normal Milestone: Needs Review
Component: Core Version: 1.8.1
Severity: major Keywords:
Cc: brett@… Difficulty:

Description

I had bug in mysql server config, with too small chunk size, and got such error:

Fatal error: spl_autoload(): Class DatabaseException could not be loaded in /var/www/html/engine/lib/database.php on line 262

I've checked two times that proper file was in proper path and readable. Server was used for a long time, and it's not the first situation when it tried to throw DatabaseException. It seems that autoloader doesn't work in shutdown handler (could it be connected to known issues with changing execution dir in shutdown functions in php?).

Info on PHP (same as CGI):

PHP 5.3.3 (cli) (built: Nov  2 2011 23:35:28)
Copyright (c) 1997-2010 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2010 Zend Technologies
    with Xdebug v2.1.2, Copyright (c) 2002-2011, by Derick Rethans

Change History (3)

comment:1 Changed 17 months ago by cash

Interesting issue. I haven't had a chance to look at this yet.

comment:2 Changed 17 months ago by cash

  • Resolution set to worksforme
  • Status changed from new to closed

I could not reproduce this. The database is not used until the class loader has been set up. I tried commenting out the check for a null query to simulate this and got the correct exception:

function execute_query($query, $dblink) {
	global $CONFIG, $dbcalls;

	//if ($query == NULL) {
		throw new DatabaseException(elgg_echo('DatabaseException:InvalidQuery'));
	//}

Also tried throwing an exception in the shutdown handler. I'll need some way to reproduce this if we're going to do anything about it.

comment:3 Changed 17 months ago by srokap

  • Resolution worksforme deleted
  • Status changed from closed to reopened

I had problems reproducing it by simply throwing an exception in db_delayedexecution_shutdown_hook(), but changing function execute_query to one below gives me an error for both linux and windows deployments:

function execute_query($query, $dblink) {
	global $CONFIG, $dbcalls;

	if ($query == NULL) {
		throw new DatabaseException(elgg_echo('DatabaseException:InvalidQuery'));
	}

	$dbcalls++;

	$result = mysql_query($query, $dblink);

	if(count(debug_backtrace())<5)
	{
		throw new DatabaseException("Test");
	}
	if (mysql_errno($dblink)) {
		throw new DatabaseException(mysql_error($dblink) . "\n\n QUERY: " . $query);
	}

	return $result;
}

Errors from

Windows:

Fatal error: Class 'DatabaseException' not found in D:\srokap\svn\airomo\workcopy\engine\lib\database.php on line 278
Call Stack
#	Time	Memory	Function	Location
1	1.2636	41961736	_elgg_session_write( )	..\sessions.php:0
2	1.2636	41962896	insert_data( )	..\sessions.php:588
3	1.2636	41963728	execute_query( )	..\database.php:520

Linux

Fatal error: spl_autoload(): Class DatabaseException could not be loaded in /var/www/html/engine/lib/database.php on line 278 
Call Stack: 
0.9472 3789612 1. _elgg_session_write() /var/www/html/engine/lib/sessions.php:0 
0.9473 3790432 2. insert_data() /var/www/html/engine/lib/sessions.php:588 
0.9473 3791020 3. execute_query() /var/www/html/engine/lib/database.php:520 

Most likely the difference in text is purely cosmetic.

Note: See TracTickets for help on using tickets.