bugsnag / bugsnag-php

BugSnag error monitoring and crash reporting tool for PHP apps
https://docs.bugsnag.com/platforms/php
MIT License
554 stars 77 forks source link

Memory exhaustion error reports are lost #619

Closed xPaw closed 3 years ago

xPaw commented 3 years ago

Looks like this:

Fatal error: Allowed memory size of 157286400 bytes exhausted (tried to allocate 20480 bytes) in somefile.php on line 172
Fatal error: Allowed memory size of 157286400 bytes exhausted (tried to allocate 20480 bytes) in Bugsnag\src\Handler.php on line 278

It's trying to allocate in shutdownHandler and it fails, so the error report about memory exhaustion is never actually reported. As a quick hack job, adding ini_set('memory_limit', '-1'); inside of shutdownHandler seems to do the trick.

Using PHP 8.0.0 and bugsnag v3.25.0

xljones commented 3 years ago

Hey @xPaw; the quick solution is to increase the memory limit as you've done. However, we'd suggest you increase the memory limit carefully to a threshold that's acceptable rather than giving your script an unlimited memory allocation with -1, as this may lead to other knock-on issues.

We're currently looking into reporting 'out of memory' errors for PHP already, so we'll be sure to let you know in this thread as soon as this is available in the Bugsnag PHP library.

GrahamCampbell commented 3 years ago

Standard trick is: https://github.com/symfony/error-handler/blob/v5.2.1/ErrorHandler.php#L113-L116.

xPaw commented 3 years ago

threshold that's acceptable rather than giving your script an unlimited memory allocation with -1

I know. I only threw that hack into bugsnag's shutdownHandler function so it can send the report.

abigailbramble commented 3 years ago

Out of Memory errors will now be reported as of v3.26.0.