Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Today I was using the ConcurrencyLimiter in my application and I noticed that it was not working as expected. I'm using it to ensure that there is only one worker executing a type of job at a time.
While running this locally with two queue workers I noticed that both workers were processing the same type of job even though I configured it to have a concurrency of only 1. After debugging I figured out it is related to the redis prefix. This prefix is now configured by default in laravel/laravel#4982 so it will affect all users using Laravel 6. Any application that is using horizon will also experience this issue as horizon is adding
horizon:
as default prefix.I've setup two queue workers while dispatching two jobs to the queue with the following script.
My log file gives the following output:
As you can see both jobs were running at the same time. After running
redis-cli monitor
these are the redis commands that are executed (by Illuminate\Redis\Limiters\ConccurencyLimiter@lockScript`):It's trying to get the lock record WITH prefix, but it's setting the lock record WITHOUT prefix.
Basically the whole concurrency check is not functioning at all at the moment when there is a redis prefix configured.
This PR makes sure the
KEYS
value is used to ensure the prefix is added when setting the lock record key.When running the same test after this change this is the output:
And
redis-cli monitor
is now showing this: