Permalink
Browse files

fix(errors): nested forward 404 calls are less likely to abruptly fail

Sometimes while drawing the error page, plugin code may request the error
page again (often code within the `pagesetup` event). We no longer fail
with an empty page on the 2nd call since this is more common that expected.

On the 3rd call we assume an infinite loop and just use a Location header
to send the user to the home page.

Fixes #9476
  • Loading branch information...
mrclay committed Mar 12, 2016
1 parent 268d055 commit 068711fad3680f5d9d431759ed895b6a48d78076
Showing with 20 additions and 8 deletions.
  1. +20 −8 engine/lib/pagehandler.php
View
@@ -244,17 +244,29 @@ function elgg_front_page_handler() {
* @return void
*/
function elgg_error_page_handler($hook, $type, $result, $params) {
static $once = 0;
$once++;
if ($once === 2) {
echo "Infinite loop attempting to show error page.";
// This draws an error page, and sometimes there's another 40* forward() call made during that
// process (usually due to the pagesetup event). We want to allow the 2nd call to pass through,
// but draw the appropriate page for the first call.
static $vars;
if ($vars === null) {
// keep first vars for error page
$vars = [
'type' => $type,
'params' => $params,
];
}
static $calls = 0;
$calls++;
if ($calls < 3) {
echo elgg_view_resource('error', $vars);
exit;
}
echo elgg_view_resource('error', [
'type' => $type,
'params' => $params,
]);
// uh oh, may be infinite loop
register_error(elgg_echo('error:404:content'));
header('Location: ' . elgg_get_site_url());
exit;
}

0 comments on commit 068711f

Please sign in to comment.