-
Notifications
You must be signed in to change notification settings - Fork 11k
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
Batch Callbacks not triggering if job timeout while in transaction #48392
Comments
Is this related to laravel/horizon#1310 |
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! |
I have been looking into this issue and found that the problem is that the transaction from the Job (tx1) is never commited neither rollback. So, when the transaction that updates the job_batches table (tx2) is launched, it will only be commited if tx1 is commited to. The solution that I found is to rollback any pending database transactions when the worker reach timeout, before any other updates. This code works. But I think there must be a "proper way" of getting the database connection in |
Laravel Version
10.23.1
PHP Version
8.1
Database Driver & Version
MariaDB 10.6.14
Description
I currently found a bug at our production servers, which leads to the fact that our job pipeline stopped.
We dispatch a batch with many jobs, these jobs are running a database transaction.
If a job fails because of a timeout (while being stuck in a transaction), the failed_jobs counter of the batch will not be increased.
Pre-analysis
To detect a timeout a pcntl alarm is used to kill the process.
framework/src/Illuminate/Queue/Worker.php
Line 214 in bfa85b8
This opens like a second thread which will mark the job as failed and increment the batch failed jobs counter.
The SQL query on the batch table will also run in a transaction.
framework/src/Illuminate/Bus/DatabaseBatchRepository.php
Line 186 in bfa85b8
For some reason unknown to me, these two transactions from different threads get in each other's way, causing the batch transaction to be rolled back.
(The mysql exporter shows a transaction savepoint in this moment)
Steps To Reproduce
The text was updated successfully, but these errors were encountered: