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

Running queue job picked up by additional workers #54711

Closed
nzkozar opened this issue Feb 19, 2025 · 4 comments
Closed

Running queue job picked up by additional workers #54711

nzkozar opened this issue Feb 19, 2025 · 4 comments

Comments

@nzkozar
Copy link

nzkozar commented Feb 19, 2025

Laravel Version

10.48.28

PHP Version

8.3

Database Driver & Version

MySQL 8.0.35-0ubuntu0.22.04.1 (Ubuntu)

Description

Queue job which starts execution on a worker, will get picked up by a 2nd worker while the 1st worker is still executing it.

I observed this behavior in one of my production projects where queue jobs process media files.
This observed, I believe unwanted behavior, results in the 2nd job pickup to fail the running job which is being executed by the first worker.

Steps To Reproduce

Queue settings:

QUEUE_CONNECTION=database

  1. Test job class
class TestJob implements ShouldQueue{
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

    public bool $failOnTimeout = true;
    public int $tries = 2;
    public int $backoff = 5;

    public int $timeout = 180;

    /** Execute the job. */
    public function handle(): void{
        Log::info("TestJob started");
        sleep(30);

        Log::info("TestJob phase 2");
        sleep(60);

        Log::info("TestJob phase 3");
        sleep(30);
        Log::info("TestJob finished");
    }

    /**
     * Handle a job failure.
     * @throws Throwable
     */
    public function failed(?Throwable $exception = null): void{
        Log::error("TestJob failed: ".$exception->getMessage());
        throw $exception;
    }
}
  1. Dispatch the job on a non-default queue:
    TestJob::dispatch()->onQueue('test');

  2. Start queue worker A and wait for it to pick up the dispatched job:
    php artisan queue:work --timeout=360 --queue=test

  3. Verify in DB jobs table, that the job is active and running.

  4. Start queue worker B in a new terminal tab and wait for it to pick up the already running job (sometimes it helps to close the new worker and start it again)
    php artisan queue:work --timeout=360 --queue=test

@crynobone
Copy link
Member

Hey there,

Unfortunately we don't support this version of the library anymore. Please check out our support policy on which versions we are currently supporting. Can you please try to upgrade to the latest version and see if your problem persists? If so, please open up a new issue and we'll help you out.

Thanks!

@macropay-solutions
Copy link

@nzkozar database queue is not recommended in prod environments anyway.

@nzkozar
Copy link
Author

nzkozar commented Feb 20, 2025

@nzkozar database queue is not recommended in prod environments anyway.

I did see this mentioned in a SO thread somewhere, but since I couldn't find any mention of this in Laravel queue documentation, I'd argue this to be a fix worthy bug.

@macropay-solutions
Copy link

macropay-solutions commented Feb 20, 2025

@nzkozar db can't handle atomic locks properly. Db queue is just for development purposes.

A fix could be adding this info in the docs.

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

No branches or pull requests

3 participants