Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[OomBootstrapper] BindingResolutionException: Target class [bugsnag] does not exist. #527

Open
wimski opened this issue Mar 9, 2023 · 3 comments
Labels
backlog We hope to fix this feature/bug in the future bug Confirmed bug

Comments

@wimski
Copy link

wimski commented Mar 9, 2023

I'm trying to use the OomBootstrapper, but I get a BindingResolutionException.

Environment

  • Bugsnag Laravel version: 2.26
    • Bugsnag version: 3.29.0
  • PHP version: 8.2.3
  • Composer version: 2.5.4
  • Laravel version: 10.0.0

Steps

  1. Install package.
composer require bugsnag/bugsnag-laravel
  1. Add the provider in app.config.
// config/app.php
[
    //...

    'providers' => [

        /*
         * Laravel Framework Service Providers...
         */
        //...

        /*
         * Package Service Providers...
         */
        Bugsnag\BugsnagLaravel\BugsnagServiceProvider::class,

        /*
         * Application Service Providers...
         */
        //...
    ],
];
  1. Add the OomBootstrapper in both kernel classes as per the documentation.
// app/Console/Kernel.php
// app/Http/Kernel.php
/**
 * @return array<int, string>
 */
protected function bootstrappers(): array
{
    return array_merge(
        [\Bugsnag\BugsnagLaravel\OomBootstrapper::class],
        parent::bootstrappers(),
    );
}

Stack trace

Details
Fatal error: Allowed memory size of 268435456 bytes exhausted (tried to allocate 266240 bytes) in /var/www/html/vendor/bugsnag/bugsnag-laravel/src/OomBootstrapper.php on line 35

Fatal error: Uncaught ReflectionException: Class "bugsnag" does not exist in /var/www/html/vendor/laravel/framework/src/Illuminate/Container/Container.php:889

Stack trace:
#0 /var/www/html/vendor/laravel/framework/src/Illuminate/Container/Container.php(889): ReflectionClass->__construct('bugsnag')
#1 /var/www/html/vendor/laravel/framework/src/Illuminate/Container/Container.php(770): Illuminate\Container\Container->build('bugsnag')
#2 /var/www/html/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(935): Illuminate\Container\Container->resolve('bugsnag', Array, true)
#3 /var/www/html/vendor/laravel/framework/src/Illuminate/Container/Container.php(706): Illuminate\Foundation\Application->resolve('bugsnag', Array)
#4 /var/www/html/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(920): Illuminate\Container\Container->make('bugsnag', Array)
#5 /var/www/html/vendor/laravel/framework/src/Illuminate/Foundation/helpers.php(120): Illuminate\Foundation\Application->make('bugsnag', Array)
#6 /var/www/html/vendor/bugsnag/bugsnag-laravel/src/OomBootstrapper.php(53): app('bugsnag')
#7 [internal function]: Bugsnag\BugsnagLaravel\OomBootstrapper->Bugsnag\BugsnagLaravel\{closure}()
#8 {main}

Next Illuminate\Contracts\Container\BindingResolutionException: Target class [bugsnag] does not exist. in /var/www/html/vendor/laravel/framework/src/Illuminate/Container/Container.php:891

Stack trace:
#0 /var/www/html/vendor/laravel/framework/src/Illuminate/Container/Container.php(770): Illuminate\Container\Container->build('bugsnag')
#1 /var/www/html/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(935): Illuminate\Container\Container->resolve('bugsnag', Array, true)
#2 /var/www/html/vendor/laravel/framework/src/Illuminate/Container/Container.php(706): Illuminate\Foundation\Application->resolve('bugsnag', Array)
#3 /var/www/html/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(920): Illuminate\Container\Container->make('bugsnag', Array)
#4 /var/www/html/vendor/laravel/framework/src/Illuminate/Foundation/helpers.php(120): Illuminate\Foundation\Application->make('bugsnag', Array)
#5 /var/www/html/vendor/bugsnag/bugsnag-laravel/src/OomBootstrapper.php(53): app('bugsnag')
#6 [internal function]: Bugsnag\BugsnagLaravel\OomBootstrapper->Bugsnag\BugsnagLaravel\{closure}()
#7 {main}

thrown in /var/www/html/vendor/laravel/framework/src/Illuminate/Container/Container.php on line 891
@wimski
Copy link
Author

wimski commented Mar 10, 2023

This seems to be a memory issue with my specific application context. My bad 😬

On second thought, here is some more information.

The issue occurs when running my PHPUnit test suite. When the OomBootstrapper is setup, memory keeps increasing during the running of the test suite until it hits the limit. If I remove the whole bootstrappers setup, the memory increase is gone and the test suite runs fine.

@wimski wimski closed this as completed Mar 10, 2023
@wimski wimski reopened this Mar 10, 2023
@wimski
Copy link
Author

wimski commented Mar 10, 2023

I have found a solution. The memory leak seems to stem from register_shutdown_function() handler being called over and over again. This little tricks makes my memory issue go away:

class OomBootstrapper
{
    protected static bool $isRegistered = false;

    public function bootstrap()
    {
        if (self::$isRegistered) {
            return;
        }

        $this->reservedMemory = str_repeat(' ', 1024 * 256);

        register_shutdown_function(function () use ($app) {
            // ...
        });

        self::$isRegistered = true;
    }
}

@johnkiely1
Copy link
Member

Hi @wimski, Thanks for raising. Glad you've found a solution for now. We're going to look into this to see what we can do to fix on our side.

@johnkiely1 johnkiely1 added bug Confirmed bug backlog We hope to fix this feature/bug in the future labels Mar 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backlog We hope to fix this feature/bug in the future bug Confirmed bug
Projects
None yet
Development

No branches or pull requests

2 participants