Skip to content

Referencing $this within batch callback depletes memory #38573

@vinnyvimto

Description

@vinnyvimto
  • Laravel Version: 8.56.0
  • PHP Version: 7.4.21
  • Database Driver & Version: mysql 5.7.32

Description:

When running a batch set of jobs and one of the callbacks (then, catch or finally) calls $this php runs out of memory.

My guess is there's some sort of recursive serialisation happening.

Steps To Reproduce:

I was able to recreate it outside of discovering the issue using the following code:

\Log::debug('Attempt batch');
\Bus::batch([
    [
        // chain these
        new JobA(),
        new JobB(),
    ]
])->then(function() {
    \Log::debug('Then callback after Job Batch succeeded');
    $this->attempts();  // comment this out and it runs fine
})->catch(function (Batch $batch, \Throwable $exception) {
    \Log::debug('Catch callback after Job Batch failed');
})->finally(function () {
    \Log::debug('Finally callback after Job Batch ran');
})->name('Example Batch')->dispatch();
\Log::debug('Completed batch');

Each of the jobs would just sleep(20).

With $this->attempts() left in the code will execute the \Log::debug('Attempt batch'); line and then crash. Commenting out $this->attempts() and everything runs as expected.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions