Pierre-Lannoy / wp-decalog

Capture and log events, metrics and traces on your site. Make WordPress observable - finally!
https://perfops.one/
GNU General Public License v3.0
64 stars 10 forks source link

Missing resilience for broken site option decalog_loggers #24

Closed JanThiel closed 2 years ago

JanThiel commented 2 years ago

Describe the bug

When for whatever reasons the sitemeta `decalog_loggers' gets corrupted, the site is doomed in an unusable state as long as decalog is enabled. Only way out: Move / Delete the Decalog plugin folder.

Happened to us when our Webservers lost connection to their DB servers due to a network outage. Seemd to be very bad timing as this one value was left filled with garbage. After the connection came back, all sites were in Fatal Error state.

I know, It's en edge case. But it is one that really hurts... Took us some time to figure out what actually was broken as our logging was broken too ... obviously ;-)

PHP Fatal error:  Uncaught Error: Call to a member function error() on null in /wp-content/plugins/decalog/includes/listeners/class-phplistener.php:350
Stack trace:
#0 [internal function]: Decalog\Listener\PhpListener->handle_exception(Object(Error))
#1 {main}
  thrown in /wp-content/plugins/decalog/includes/listeners/class-phplistener.php on line 350
Fatal error: Uncaught Error: Call to a member function error() on null in /wp-content/plugins/decalog/includes/listeners/class-phplistener.php:350
Stack trace:
#0 [internal function]: Decalog\Listener\PhpListener->handle_exception(Object(Error))
#1 {main}
  thrown in /wp-content/plugins/decalog/includes/listeners/class-phplistener.php on line 350

To Reproduce Steps to reproduce the behavior:

  1. Configure decalog
  2. Go to the DB table wp_sitemeta search for decalog_loggers
  3. Put something invalid like A.3.0 in there (there should be a serialized object / array in it in a valid case)
  4. If the WordPress Fatal Handler "rescues" you, you are lucky :) If you have it disabled to handle errors yourselves, you end up in this trap. Maybe you will end up there anyway when decalog tries to log the fatal caused by itself 🤔

Expected behavior Only initialize decalog if all required settings are there AND contain valid data. If invalid data is found, delete, skip, ignore or reset that data instead of continuing initialization with broken data. Or deactivate the plugins. Self-Healing should be technically easy in this case.

Environment (please complete the following information):

Best Regards!

Pierre-Lannoy commented 2 years ago

Hello @JanThiel ! Sorry to hear you had such hard times…

And yes, for now, in such case you have to manually "remove" DecaLog.

I think your mishap is an opportunity to implement a failsafe in the next version… Let me think about it…

JanThiel commented 2 years ago

Not your fault :-) These things happen! I have a PR ready with a possible solution. Then we can discuss about it :-)

Pierre-Lannoy commented 2 years ago

Thanks for the PR, Jan! I will merge it and add the failsafe I have in mind… Thank you so much!