Skip to content

MongodbQueueServiceProvider.php connects to MongoDB for failed logs even when failed log storage is disabled #2356

Closed
@robjbrain

Description

@robjbrain
  • Laravel-mongodb Version: 3.8
  • PHP Version: 8.0

Description:

In MongodbQueueServiceProvider there is a check done for the config queue.failed.database which then connects to the Mongo DB if true.

$this->app['db']->connection(config('queue.failed.database'))->getDriverName() == 'mongodb'

However it is possible to disable the failed log storage whilst still having a value in the queue.failed.database config.

Disabling Failed Job Storage

You may instruct Laravel to discard failed jobs without storing them by setting the queue.failed.driver configuration option's value to null. Typically, this may be accomplished via the QUEUE_FAILED_DRIVER environment variable:

QUEUE_FAILED_DRIVER=null

In these cases, since you're only checking the queue.failed.database config it will still attempt to connect.

Steps to reproduce

I can't produce specific steps that cause a bug since my exact circumstances are unusual, but it should be obvious that a check should be done if the failed log storage is disaled.

You can verify what i'm saying via the following:

  1. Edit config/queue.php in a Laravel to application to the following
        //'driver' => env('QUEUE_FAILED_DRIVER', 'database-uuids'),
        'driver' => null,
        'database' => env('DB_CONNECTION', 'mysql'),
  1. Edit \Jenssegers\Mongodb\Connection to
    public function __construct(array $config)
    {
        dd(debug_backtrace());
  1. Run the app and note that it is being called from mongodb/src/MongodbQueueServiceProvider.php:16 in the 4th Backtrace.

  2. Edit config/database.php again

        //'driver' => env('QUEUE_FAILED_DRIVER', 'database-uuids'),
        'driver' => null,
        //'database' => env('DB_CONNECTION', 'mysql'),
        'database' => null,
  1. Run the app and note that this time MongoDB is not being called at all, or being called from a Database Provider rather than a Queue Provider.

Expected behaviour

The Queue Provider should not connect to Mongo DB if Failed Log Storage is disabled.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions