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

Queue job implementing ShouldQueue and ShouldBeUnique dispatched via dispatch()->afterResponse() acquires lock and never releases #46537

Closed
spiechu opened this issue Mar 21, 2023 · 4 comments

Comments

@spiechu
Copy link

spiechu commented Mar 21, 2023

  • Laravel Version: 9.39.0
  • PHP Version: 8.1.8
  • Database Driver & Version: MariaDB

Description:

Queue job implementing ShouldQueue and ShouldBeUnique and dispatched via Job::dispatch()->afterResponse()
acquires lock using UniqueLock in PendingDispatch::shouldDispatch().
Then job is run using app(Dispatcher::class)->dispatchAfterResponse($this->job).
After job is done there is nothing that runs something similar to CallQueuedHandler::ensureUniqueJobLockIsReleased().

Steps To Reproduce:

  1. Create queue job implementing ShouldQueue, ShouldBeUnique
  2. Implement uniqueId()
  3. Dispatch via Job::dispatch()->afterResponse()
  4. Dispatch again via Job::dispatch()->afterResponse() and it will not work since lock is still acquired.
@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!

@cosmastech
Copy link
Contributor

Assuming the PR I put up doesn't get merged, I believe you can resolve this by adding:

Bus\Dispatcher::map([YourJob::class => YourUniqueJobHandler::class]);

To your AppServiceProvider@boot() method. The UniqueJobHandler class should have either a handle() or __invoke() method that receives YourJob $job and handles running the job and deleting the lock if successful.

@cosmastech
Copy link
Contributor

@driesvints should this be marked as closed?

@driesvints
Copy link
Member

Thanks!

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

No branches or pull requests

3 participants