Skip to content

Fix null worker crash in Swoole during code reload#1110

Draft
JoshSalway wants to merge 1 commit intolaravel:2.xfrom
JoshSalway:fix/swoole-null-worker-check
Draft

Fix null worker crash in Swoole during code reload#1110
JoshSalway wants to merge 1 commit intolaravel:2.xfrom
JoshSalway:fix/swoole-null-worker-check

Conversation

@JoshSalway
Copy link
Copy Markdown

@JoshSalway JoshSalway commented Mar 22, 2026

Summary

Fixes a crash in Swoole's request handler where $workerState->worker or $workerState->client is null during file watcher reloads, causing a fatal "Call to a member function handle() on null" error.

Fixes #1053

Problem

When Swoole's file watcher triggers a reload, there is a brief window where the worker state is being re-initialized. Requests arriving during this window hit a null $workerState->worker, causing:

Fatal error: Call to a member function handle() on null
  vendor/laravel/octane/src/Swoole/SwooleRequestHandler.php

This crashes the entire worker process rather than gracefully handling the transient state.

Solution

Add a null guard for $workerState->worker and $workerState->client in the Swoole request handler. If either is null (worker still initializing after reload), return a 503 Service Unavailable response instead of crashing.

Before/After

Before: Requests during reload window cause a fatal error, killing the worker process.

After: Requests during reload window receive a 503 response. Normal requests work immediately after the reload completes.

Test Plan

  • Start Octane with Swoole and file watcher enabled
  • Make a code change to trigger a reload
  • Send requests during the reload window -- should get 503 instead of fatal error
  • Verify normal requests resume after reload completes

When using the file watcher with Swoole, the worker process is briefly
destroyed and recreated during hot-reload. If a request arrives during
this window, accessing the null worker/client properties causes a fatal
error. This adds a null guard that returns a 503 response instead.

Fixes laravel#1053

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@github-actions
Copy link
Copy Markdown

Thanks for submitting a PR!

Note that draft PRs 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.

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.

Call to a member function handle on null (Swoole)

1 participant