Skip to content

Fix worker being killed 15s after a job calls Artisan::call() - #4

Merged
tevkert merged 2 commits into
tevkert:mainfrom
aligulzar729:fix/watchdog-nested-artisan-call
Nov 19, 2026
Merged

tevkert merged 2 commits into
tevkert:mainfrom
aligulzar729:fix/watchdog-nested-artisan-call

Conversation

@aligulzar729

Copy link
Copy Markdown
Contributor

A job that calls Artisan::call() and then keeps working for more than 15 seconds gets its worker killed mid-job. Stock workers are fine.

The exit watchdog is armed on CommandFinished, and Laravel fires that for Artisan::call() too. So the watchdog starts counting inside the job and replaces the worker's own SIGALRM timeout handler. 15s later the worker dies. The job isn't marked failed, it just runs again after retry_after.

To reproduce:

public function handle(): void
{
    Artisan::call('env');
    sleep(20); // worker is killed at 15s
}

The fix: arm the watchdog from the console kernel's terminate() instead. Laravel only calls that once, after the command the process was started for. Artisan::call() never gets there. On Laravel 11.18+ that's the Terminating event, on older 11.x it's $app->terminating().

Added a calls-artisan fixture and a test in StockParityTest. It times out on main and passes here. Unit, Mechanics and the Integration suite (host mode) pass.

I haven't run the older-Laravel fallback on a real 11.0 install, only read the kernel code for it.

aligulzar729 and others added 2 commits November 19, 2026 12:16
The exit watchdog listener is shared by Horizon's forked workers and plain
queue:work workers, so the same job killed a queue:work worker 15 s after its
Artisan::call(). The test fails on main and passes with the fix.
@tevkert

tevkert commented Nov 19, 2026

Copy link
Copy Markdown
Owner

Thanks Ali, great catch and a very clear write-up. You're right: Artisan::call() fires CommandFinished too, so the exit watchdog was armed in the middle of the job and replaced the worker's own timeout handler. The kernel's terminate is the right place for it.

I reproduced it and pushed one commit on top of yours:

  • Plain queue:work workers had the same bug, since they share that listener. QueueWorkStockParityTest now has the same test; it fails on main and passes with your fix.
  • docker/README.md now says the default fixtures:dispatch skips calls-artisan too.

The Horizon and queue:work integration suites pass. I'll merge once CI is green and ship it in 1.1.1.

@tevkert
tevkert merged commit 77abce4 into tevkert:main Nov 19, 2026
27 checks passed
tevkert added a commit that referenced this pull request Nov 19, 2026
A job that calls Artisan::call() and keeps working past exit_grace no longer
gets its worker killed: the exit watchdog is armed when the console kernel
terminates instead of on CommandFinished (#4). CHANGELOG for 1.1.1.
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.

2 participants