Closed tklie closed 1 year ago
This only happens when the applications are configured to use the same Redis DB for their queues.
You can't use the same Redis DB for different Horizon setups, this is not supported sorry. Please see https://laravel.com/docs/10.x/horizon#configuration
Horizon Version
5.16.1
Laravel Version
10.13.5
PHP Version
8.2
Redis Driver
Predis
Redis Version
4.0.9
Database Driver & Version
No response
Description
I am running multiple Laravel applications connected to the same Redis, each using their own Horizon. I am currently facing an issue, where jobs randomly get stuck in the pending state (according to the dashboard) without ever being processed.
This only happens when the applications are configured to use the same Redis DB for their queues. As far as I can tell, this seems to be caused by the keys for the queues not being prefixed with the
HORIZON_PREFIX
. Thus, all Horizon instances are trying to migrate jobs fromdelayed
orreserved
tonotify
at the exact same time, seemingly causing race conditions / deadlocks - especially if some of the applications have queues with the same name.The
Laravel\Horizon\RedisQueue
extends theIlluminate\Queue\Queue
, but does not override thegetQueue
method., which would be an, at first glance, obvious approach to fix this:Before submitting a PR, I wanted to ask if there is a specific reason this has not been done.
Steps To Reproduce
ShouldBeUniqueUntilProcessing
;delay
is not relevant for the issue to occur, this also happens to non-delayed jobs)Redis CLI
On inspecting the Redis CLI we notice that anything written to the Meta DB gets properly prefixed with the
HORIZON_PREFIX
- anything in the Queue DB does not. I think this might be causing the issue, correct me if I'm wrong.Temporary solution
What solves the issue, is setting the queue connections for each application to different databases:
Configuration
Same for the other 3 applications.