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

TypeError: array_diff(): Argument #1 ($array) must be of type array, null given in /vendor/laravel/framework/src/Illuminate/Bus/DatabaseBatchRepository.php:143 #46580

Closed
naciriii opened this issue Mar 24, 2023 · 2 comments · Fixed by #46581

Comments

@naciriii
Copy link
Contributor

  • Laravel Version: 10.3.3
  • PHP Version: 8.2.4
  • Database Driver & Version: Mysql 8

Description:

similar to #46327
this is basically related to : $batch->failed_job_ids is null thus array_diff will fail on null

 public function decrementPendingJobs(string $batchId, string $jobId)
    {
        $values = $this->updateAtomicValues($batchId, function ($batch) use ($jobId) {
            return [
                'pending_jobs' => $batch->pending_jobs - 1,
                'failed_jobs' => $batch->failed_jobs,
                'failed_job_ids' => json_encode(array_values(array_diff(json_decode($batch->failed_job_ids, true), [$jobId]))),
            ];
        });

        return new UpdatedBatchJobCounts(
            $values['pending_jobs'],
            $values['failed_jobs']
        );
    }

and also here with same case

 /**
     * Increment the total number of failed jobs for the batch.
     *
     * @param  string  $batchId
     * @param  string  $jobId
     * @return \Illuminate\Bus\UpdatedBatchJobCounts
     */
    public function incrementFailedJobs(string $batchId, string $jobId)
    {
        $values = $this->updateAtomicValues($batchId, function ($batch) use ($jobId) {
            return [
                'pending_jobs' => $batch->pending_jobs,
                'failed_jobs' => $batch->failed_jobs + 1,
                'failed_job_ids' => json_encode(array_values(array_unique(array_merge(json_decode($batch->failed_job_ids, true), [$jobId])))),
            ];
        });

        return new UpdatedBatchJobCounts(
            $values['pending_jobs'],
            $values['failed_jobs']
        );
    }

Steps To Reproduce:

  • Cannot easily reproduced since it doesn't occur only on interruptions but can be reproduced as below manually:
  • Create a batch and run it through cli or whatever
  • Run the queue worker for a couple of seconds (until one of the jobs was executed at least)
  • stop the worker
  • Check the database table and overwrite the failed_job_ids column in job_batches table and set it to NULL or empty string
  • Make the next job to run fail explicitly
  • Run the queue worker
  • Check the failed_jobs table or the logs file you 'll get the same exception as mentioned above in description
@github-actions
Copy link

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!

@naciriii
Copy link
Contributor Author

Pushing a fix in 5 minutes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants