Skip to content

Fix queue:listen timeout false positives after system sleep/wake - #58216

Merged
taylorotwell merged 2 commits into
laravel:12.xfrom
ranjith67:fix-queue-listen-timeout
Dec 28, 2025
Merged

taylorotwell merged 2 commits into
laravel:12.xfrom
ranjith67:fix-queue-listen-timeout

Conversation

@ranjith67

Copy link
Copy Markdown
Contributor

Description

Fixes issue where queue:listen command crashes with a timeout error after the system wakes from sleep, even when no jobs are running.

Related Issue: #58178

Problem

The queue:listen command was creating a single Process object outside the loop and reusing it for each iteration. When the system goes to sleep:

  1. Wall-clock time (microtime(true)) continues to advance
  2. The process is suspended
  3. When the system wakes up, Symfony Process checks if microtime(true) - starttime > timeout
  4. It sees too much wall-clock time has passed and throws a ProcessTimedOutException, even though the process was suspended

This caused false timeout errors after system sleep/wake cycles, crashing composer run dev after a few hours.

Solution

Moved the Process object creation inside the listen() method's loop, ensuring each iteration creates a fresh Process instance with a clean timeout state.

Before:

public function listen($connection, $queue, ListenerOptions $options)
{
    $process = $this->makeProcess($connection, $queue, $options); // Created once
    
    while (true) {
        $this->runProcess($process, $options->memory); // Reused
        // ...
    }
}

After:

public function listen($connection, $queue, ListenerOptions $options)
{
    while (true) {
        $process = $this->makeProcess($connection, $queue, $options); // Fresh each iteration
        $this->runProcess($process, $options->memory);
        // ...
    }
}

Impact

  • ✅ Prevents false timeout errors after system sleep/wake cycles
  • ✅ Each queue:work --once invocation gets a fresh Process with clean timeout state
  • ✅ Timeout protection still works correctly for actually stuck processes
  • ✅ No breaking changes - maintains existing behavior and API

Testing

  • ✅ Existing tests pass
  • ✅ Verified that makeProcess() creates new Process instances each call
  • ✅ Confirmed timeout values are correctly set on each Process instance

Notes

This fix ensures that the timeout counter starts fresh for each subprocess invocation, preventing accumulated wall-clock time during system sleep from causing false positives.

ranjith67 and others added 2 commits December 27, 2025 19:32
Fixes laravel#58178

The queue:listen command was creating a single Process object outside
the loop and reusing it for each iteration. When the system goes to
sleep, wall-clock time continues to advance while the process is
suspended. Upon wake, Symfony Process checks if too much wall-clock
time has passed and throws a ProcessTimedOutException, even though
the process was suspended.

By moving Process creation inside the loop, each iteration now gets
a fresh Process instance with a clean timeout state. This prevents
false timeout errors after system sleep/wake cycles while maintaining
proper timeout protection for actually stuck processes.

Changes:
- Move Process creation inside listen() method's while loop
- Each queue:work --once invocation now gets a fresh Process object
- Timeout counter starts fresh for each subprocess invocation
@taylorotwell
taylorotwell merged commit f4c6d2c into laravel:12.x Dec 28, 2025
70 checks passed
@taylorotwell

taylorotwell commented Dec 28, 2025 •

Copy link
Copy Markdown
Member

This actually doesn't fix the issue for me locally. Reverting.

@ranjith67

Copy link
Copy Markdown
Contributor Author

Thanks for checking and confirming, Taylor — appreciate you taking the time to test and revert.

I’ll pause on this for now and revisit if I’m able to reproduce the behavior more reliably across environments. Thanks again.

akyrey pushed a commit to akyrey/framework that referenced this pull request Dec 29, 2025
…avel#58216)

* Fix queue:listen timeout false positives after system sleep/wake

Fixes laravel#58178

The queue:listen command was creating a single Process object outside
the loop and reusing it for each iteration. When the system goes to
sleep, wall-clock time continues to advance while the process is
suspended. Upon wake, Symfony Process checks if too much wall-clock
time has passed and throws a ProcessTimedOutException, even though
the process was suspended.

By moving Process creation inside the loop, each iteration now gets
a fresh Process instance with a clean timeout state. This prevents
false timeout errors after system sleep/wake cycles while maintaining
proper timeout protection for actually stuck processes.

Changes:
- Move Process creation inside listen() method's while loop
- Each queue:work --once invocation now gets a fresh Process object
- Timeout counter starts fresh for each subprocess invocation

* Update Listener.php

---------

Co-authored-by: Taylor Otwell <taylor@laravel.com>
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