Opened 3 years ago

Closed 3 years ago

Last modified 3 years ago

#2499 closed Bug (fixed)

ErrorHandler - Nesting level too deep - recursive dependency

Reported by: peterb Owned by:
Priority: critical Milestone: 1.5.1 Piwik 1.5.1
Component: Core Keywords:
Cc: Sensitive: no

Description (last modified by matt)

See reportings in http://forum.piwik.org/read.php?5,77659 and http://forum.piwik.org/read.php?5,78118.

Reason for the error seems to be the use of var_export in connection with debug_backtrace, see http://bugs.php.net/bug.php?id=30471 (bugs.php.net down atm)

PHP 5.2

Other configurations affected, see below

Attachments (3)

dump.html (39.1 KB) - added by ferment 3 years ago.
var_dump($bt) from core/ErrorHandler.php
Refs_#2499.patch (570 bytes) - added by peterb 3 years ago.
Thanks for the dump, ferment. The "Nesting level too deep"-Problem has nothing to do with other classes of piwik. It is a problem when one of the other classes throw an error, and contain a reference to itself (e.g. method chaining, &$object definition, etc.). This is often used within frameworks. Since var_export is not able to limit the depth of nesting, I propose the following patch for the ErrorHandler.
errors.html (76.0 KB) - added by GoSnA 3 years ago.
Applying this Patch doesn't work for me komplete, now i got many errors, see attachment.

Download all attachments as: .zip

Change History (18)

comment:1 follow-up: Changed 3 years ago by peterb (peterbo)

  • Description modified (diff)

comment:2 in reply to: ↑ 1 Changed 3 years ago by ferment

Replying to peterb:

I'm using PHP 5.1.6 and just started getting this problem with my upgrade to Piwik 1.5 from 1.4.

Using XDebug, I tracked it down to a problem with Zend_Session. It's failing to write sessions to the database table, possibly because the database handle is no longer available when Zend_Session::writeClose() is called in the destructor of Zend_Session_SaveHandler_DbTable (I'm not 100% certain.)

At any rate, I changed the file core/Session.php, adding:

register_shutdown_function(array( "Zend_Session", "writeClose" ), true);

...after the line:

Zend_Session::start();

...and it now seems to work for me (no more nesting level errors, and I can also log into Piwik again.) But I haven't tested it on any other version of PHP.

comment:3 follow-ups: Changed 3 years ago by peterb (peterbo)

ferment, could you please tell us, what a var_dump($bt) injected into the file core/ErrorHandler.php (directly before, after or instead of the line "array_shift($bt);" echos? I think we would be a step further then, because there is somehow a recursion in that context, i suppose.

comment:4 Changed 3 years ago by GoSnA

On my side, the adding of register_shutdown_function doesn't work.

I have Piwik running with cronjobs and the error is only coming in the cronjob via email. Login into the Piwik web webinterface works without problems.

PHP Fatal error:  Nesting level too deep - recursive dependency? in /srv/www/vhosts/xxx.de/subdomains/piwik/httpdocs/core/ErrorHandler.php on line 36
PHP Fatal error:  Nesting level too deep - recursive dependency? in /srv/www/vhosts/xxx.de/subdomains/piwik/httpdocs/core/ErrorHandler.php on line 36
PHP Fatal error:  Nesting level too deep - recursive dependency? in /srv/www/vhosts/xxx.de/subdomains/piwik/httpdocs/core/ErrorHandler.php on line 36
PHP Fatal error:  Nesting level too deep - recursive dependency? in /srv/www/vhosts/xxx.de/subdomains/piwik/httpdocs/core/ErrorHandler.php on line 36

comment:5 Changed 3 years ago by GoSnA

Removing the line 36 brings out the following error:

Notice: Undefined offset: 7 in /srv/www/vhosts/pantanet.de/subdomains/piwik/httpdocs/core/ArchiveProcessing/Day.php on line 671 
#0 Piwik_ErrorHandler() called at [/srv/www/vhosts/xxx.de/subdomains/piwik/httpdocs/core/ArchiveProcessing/Day.php:671]
#1 Piwik_ArchiveProcessing_Day->updateInterestStats() called at [/srv/www/vhosts/xxx.de/subdomains/piwik/httpdocs/plugins/CustomVariables/CustomVariables.php:165]
#2 Piwik_CustomVariables->archiveDayAggregate() called at [/srv/www/vhosts/xxx.de/subdomains/piwik/httpdocs/plugins/CustomVariables/CustomVariables.php:138]
#3 Piwik_CustomVariables->archiveDay() called at [:]
#4 call_user_func_array() called at [/srv/www/vhosts/xxx.de/subdomains/piwik/httpdocs/libs/Event/Dispatcher.php:284]
#5 Event_Dispatcher->postNotification() called at [/srv/www/vhosts/xxx.de/subdomains/piwik/httpdocs/core/PluginsManager.php:609]
#6 Piwik_PostEvent() called at [/srv/www/vhosts/xxx.de/subdomains/piwik/httpdocs/core/ArchiveProcessing/Day.php:42]
#7 Piwik_ArchiveProcessing_Day->compute() called at [/srv/www/vhosts/xxx.de/subdomains/piwik/httpdocs/core/ArchiveProcessing.php:429]
#8 Piwik_ArchiveProcessing->launchArchiving() called at [/srv/www/vhosts/xxx.de/subdomains/piwik/httpdocs/core/Archive/Single.php:217]
#9 Piwik_Archive_Single->prepareArchive() called at [/srv/www/vhosts/xxx.de/subdomains/piwik/httpdocs/core/Archive/Single.php:246]
#10 Piwik_Archive_Single->get() called at [/srv/www/vhosts/xxx.de/subdomains/piwik/httpdocs/core/Archive/Single.php:424]
#11 Piwik_Archive_Single->getNumeric() called at [/srv/www/vhosts/xxx.de/subdomains/piwik/httpdocs/core/Archive/Array.php:89]
#12 Piwik_Archive_Array->getNumeric() called at [/srv/www/vhosts/xxx.de/subdomains/piwik/httpdocs/plugins/VisitsSummary/API.php:110]
#13 Piwik_VisitsSummary_API->getNumeric() called at [/srv/www/vhosts/xxx.de/subdomains/piwik/httpdocs/plugins/VisitsSummary/API.php:116]
#14 Piwik_VisitsSummary_API->getVisits() called at [:]
#15 call_user_func_array() called at [/srv/www/vhosts/xxx.de/subdomains/piwik/httpdocs/core/API/Proxy.php:179]
#16 Piwik_API_Proxy->call() called at [/srv/www/vhosts/xxx.de/subdomains/piwik/httpdocs/core/API/Request.php:121]
#17 Piwik_API_Request->process() called at [/srv/www/vhosts/xxx.de/subdomains/piwik/httpdocs/plugins/API/Controller.php:27]
#18 Piwik_API_Controller->index() called at [:]
#19 call_user_func_array() called at [/srv/www/vhosts/xxx.de/subdomains/piwik/httpdocs/core/FrontController.php:127]
#20 Piwik_FrontController->dispatch() called at [/srv/www/vhosts/xxx.de/subdomains/piwik/httpdocs/index.php:53]

Changed 3 years ago by ferment

var_dump($bt) from core/ErrorHandler.php

comment:6 in reply to: ↑ 3 Changed 3 years ago by ferment

Replying to peterb:

ferment, could you please tell us, what a var_dump($bt) injected into the file core/ErrorHandler.php (directly before, after or instead of the line "array_shift($bt);" echos? I think we would be a step further then, because there is somehow a recursion in that context, i suppose.

Sure. I've attached a copy of the dump to the thread.

comment:7 in reply to: ↑ 3 Changed 3 years ago by ferment

Replying to peterb:

I think what might be happening is that var_export() is getting stuck on a circular reference in one of the $bt args. I ran across a forum discussion about this while searching:

http://forum.kohanaframework.org/discussion/1631/var_dump-print_r-var_export/p1

Changed 3 years ago by peterb (peterbo)

Thanks for the dump, ferment. The "Nesting level too deep"-Problem has nothing to do with other classes of piwik. It is a problem when one of the other classes throw an error, and contain a reference to itself (e.g. method chaining, &$object definition, etc.). This is often used within frameworks. Since var_export is not able to limit the depth of nesting, I propose the following patch for the ErrorHandler.

comment:8 Changed 3 years ago by peterb (peterbo)

Anthon, do we need to store executable PHP code in the logger (to reuse it somewhere for example), or would this patch make sense?

Changed 3 years ago by GoSnA

Applying this Patch doesn't work for me komplete, now i got many errors, see attachment.

comment:9 Changed 3 years ago by peterb (peterbo)

@GoSnA: yes, that's correct. As I stated, this is not related to the error that triggers the ErrorHandler. Now the Errors are displayed / handled correctly and we can track down the real root of the error(s).

comment:10 Changed 3 years ago by vipsoft (robocoder)

  • Milestone set to 1.6 Piwik 1.6

Thanks Peter. I'll have to look at the preg_replace, but this evidently works better than var_export.

We should fix the Notices being emitted too.

comment:11 Changed 3 years ago by peterb (peterbo)

GoSnA, this is strange - please make sure, all piwik files have been correctly updated to the newest version.

comment:12 Changed 3 years ago by matt (mattab)

  • Description modified (diff)
  • Priority changed from major to critical
  • Summary changed from PHP 5.2, Nesting level too deep - recursive dependency? to PHP 5.x, Nesting level too deep - recursive dependency?

Could this somehow be linked to #2491 ?

comment:13 Changed 3 years ago by vipsoft (robocoder)

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

(In [4949]) fixes #2499, refs #2409

comment:14 Changed 3 years ago by hass

I strongly suggest to release 1.6 ASAP or at least 1.5.1 with this patch applied... My piwik was also broken and I fixed it by uploading the latest errorhandler.php.

comment:15 Changed 3 years ago by vipsoft (robocoder)

  • Summary changed from PHP 5.x, Nesting level too deep - recursive dependency? to ErrorHandler - Nesting level too deep - recursive dependency
Note: See TracTickets for help on using tickets.