bugsnag-laravel: PHP Fatal error: Allowed Memory Size

On a few occasions where I imagine the stack trace is large, BugsnagLogger is unable to log the error and fails with PHP Fatal error: Allowed Memory Size. This means the original error is lost for good since it isn’t logger and the PHP error logs don’t end up showing this error either as the request fails fatally.

Some kind of check or config option to circumvent this would be very helpful.

About this issue

  • Original URL
  • State: open
  • Created 7 years ago
  • Reactions: 5
  • Comments: 27 (12 by maintainers)

Most upvoted comments

See also #19 etc.

are you certain that this is caused by Bugsnag, and not Bugsnag trying to catch the out of memory error, caused by your app

Both of those cases are problematic (and my logs indicate both occur).

The Bugsnag client allocates significant amounts of memory in many places. Everything from the static array in ErrorTypes allocating 32k, to the json_encode() in HttpClient using essentially unbound memory (I’ve seen megabytes there).

So, both cases happen:

  • sometimes an error just coincidentally happens when memory usage is near the limit and, were it not for Bugsnag’s allocations, the error would have been otherwise handled normally
  • sometimes something else in the app runs out of memory, and BugSnag tries to report the error and then hits a second OOM error

Both result in nothing in Bugsnag. Obviously the first case is purely caused by BugSnag, but the second is pretty poor form too.

In fact, unless the Bugsnag client checks memory_get_usage(), and optionally issues an ini_set() (to account for the extra memory that’s about to be allocated), I don’t see how comments like https://github.com/bugsnag/bugsnag-laravel/issues/19#issuecomment-49816769 (“looks like bugsnag-php should be able to catch memory errors”) can be correct…

Maybe PHP used to disable the memory limit after the first time it hit it? It certainly doesn’t any longer.

The most common cases I see are accidental infinite recursion in Eloquent, or the service container. I mean, they are all valid cases, so. We need to keep them all in mind. 😃