laravel / framework

The Laravel Framework.
https://laravel.com
MIT License
31.81k stars 10.77k forks source link

Closure in job chain is not called if preceded by job batch #51897

Open eldair opened 1 week ago

eldair commented 1 week ago

Laravel Version

11.11.1

PHP Version

8.3.8

Database Driver & Version

No response

Description

Closure in job Bus::chain is not called if it is after Bus::batch - exception is thrown but there is nothing in failed jobs. Call to undefined method Closure::getClosure() {"exception":"[object] (Error(code: 0): Call to undefined method Closure::getClosure() at /home/eldair/code/bus_chain_test/vendor/laravel/framework/src/Illuminate/Queue/CallQueuedClosure.php:107)

Steps To Reproduce

Batch setup

$batch = [];
for ($i=0; $i < 5; $i++) {
    $batch[] = new BatchJob($i + 1);
}

This will throw the exception and the closure will not be called

Bus::chain([
    new ChainedJob,
    Bus::batch($batch),
    function () {
        logger('after batch');
    }
])->dispatch();

This works fine

Bus::chain([
    new ChainedJob,
    Bus::batch($batch),
    new ChainedJob,
    function () {
        logger('after batch');
    }
])->dispatch();

Here is the reproduction repo https://github.com/eldair/bus_chain_test/tree/main, nothing was added except two jobs and console command to call the code above.

github-actions[bot] commented 6 days ago

Thank you for reporting this issue!

As Laravel is an open source project, we rely on the community to help us diagnose and fix issues as it is not possible to research and fix every issue reported to us via GitHub.

If possible, please make a pull request fixing the issue you have described, along with corresponding tests. All pull requests are promptly reviewed by the Laravel team.

Thank you!

Dry7 commented 2 days ago

In my opinion, the problem is that the serializable-closure library incorrectly handles the case when SerializableClosure is used as a property type inside another SerializableClosure.

This case is happening here https://github.com/laravel/framework/blob/94df3d60c9a6c2e6fdb47202d979fc92d339a5f8/src/Illuminate/Bus/ChainedBatch.php#L131

I fixed the issue in this pull request https://github.com/laravel/serializable-closure/pull/86

I think this bug will be fixed when my pull request is accepted