Skip to content

[12.x] Add ability to control QueueWorker memory exceeded exit code#57044

Merged
taylorotwell merged 13 commits into
laravel:12.xfrom
jackbayliss:memory-exit-code
Sep 15, 2025
Merged

[12.x] Add ability to control QueueWorker memory exceeded exit code#57044
taylorotwell merged 13 commits into
laravel:12.xfrom
jackbayliss:memory-exit-code

Conversation

@jackbayliss

@jackbayliss jackbayliss commented Sep 12, 2025

Copy link
Copy Markdown
Contributor

This PR adds the ability to control the memory exceeded exit code.

Any exit code other than 1 is treated as an error. Currently, Laravel uses a hard coded exit code of 12 for memory limits, which can trigger infrastructure-level consequences on some managed hosting platforms.

Real case scenario :

  • I have many workers running

  • I can only have so much memory between them

  • Occasionally - depending on the amount of jobs a worker may hit a memory limit and exit - it's restarted.

  • The managed hosting provider restarts the whole worker container after 3x errors within 24 hrs (memory limits included) which make all the workers restart, even if they're working through something.

  • I basically want to force a success if this happens, so I'd use 0 as it'll restart as expected, but with no infrastructure consequences

  • Kept the constant in place for backward compatibility (in case anyone extends Worker and relies on it).

  • Added a test to confirm the static works.

Any thoughts or improvements lmk 🫡

@github-actions

Copy link
Copy Markdown

Thanks for submitting a PR!

Note that draft PR's are not reviewed. If you would like a review, please mark your pull request as ready for review in the GitHub user interface.

Pull requests that are abandoned in draft may be closed due to inactivity.

@jackbayliss jackbayliss marked this pull request as ready for review September 15, 2025 09:09
@taylorotwell taylorotwell merged commit b4d8576 into laravel:12.x Sep 15, 2025
63 checks passed
tegos pushed a commit to tegos/laravel-framework that referenced this pull request Sep 28, 2025
…aravel#57044)

* init

* Update WorkCommand.php

* cs

* fix up test

* init

* Update WorkCommandTest.php

* try fix flakiness

* cs

* Update WorkCommandTest.php

* Update WorkCommandTest.php

* readd const to prevent breaking change

:trollface:

* use variable

---------

Co-authored-by: Taylor Otwell <taylor@laravel.com>
@AhmedAlaa4611

Copy link
Copy Markdown
Contributor

Hello @jackbayliss

For using the new $memoryExceededExitCode, should we just override the static property directly in the boot method of the application's AppServiceProvider, or am I missing something?

use Illuminate\Queue\Worker;

/**
 * Bootstrap any application services.
 */
public function boot(): void
{
    Worker::$memoryExceededExitCode = 25;
}

@jackbayliss

Copy link
Copy Markdown
Contributor Author

@AhmedAlaa4611 Correct :) - or that's at least what I do 🤓

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

Successfully merging this pull request may close these issues.

3 participants