Skip to content

HttpServer::stop() unsupported in pool mode (workers > 1) — cross-thread shutdown not wired up #117

Closed

Description

@EdmondDantes

Problem

HttpServer::stop() throws when called on a pool-parent server (config->setWorkers(N) with N > 1):

// src/http_server_class.c, ZEND_METHOD(TrueAsync_HttpServer, stop)
if (server->in_pool_mode) {
    zend_throw_exception(http_server_runtime_exception_ce,
        "stop() on a pool-parent HttpServer is not supported yet "
        "(issue #11). Stop each worker from within its own handler.", 0);
    RETURN_FALSE;
}

Each pool worker runs its own cloned HttpServer PHP object in its own thread (pool_worker_handler calls start() on the transferred clone), so the parent's stop() has no way to reach them — there is currently no cross-thread signal for "shut down and don't come back."

Found while adding graceful shutdown (Async\signal(SIGTERM/SIGINT) → stop()) to laravel-spawn's TrueAsyncServer: it works correctly for workers=1 (standalone path, not pool mode), but production configs typically run Async\available_parallelism() workers, which hits this exception.

Referenced as "issue #11" in the code comment, but #11 itself (built-in worker pool) is closed — this specific cross-thread-stop gap was never split out into its own tracked issue.

Why this shouldn't be hard

HttpServer::reload() (issue #93, shipped) already solves the identical cross-thread coordination problem for hot-reload:

  • Bumps a shared reload_shared->epoch (atomic).
  • Each worker notices the bump on its own tick and retires itself.
  • The parent awaits every worker's exit via the existing pool_await_state/all_done mechanism (the same one start()'s own pool-launch path suspends on).
  • Only after the old cohort has fully drained does reload() submit a fresh cohort.

A pool-mode stop() needs the same "workers notice a shared flag on their tick, drain, exit, parent awaits all_done" path, just without the final "submit a fresh cohort" step.

Proposed approach

  1. Add a stopping flag alongside (or reusing) reload_shared, checked wherever a worker currently polls epoch on its tick.
  2. On that flag, a worker drains and exits (same graceful-shutdown path a standalone stop() already takes) instead of reloading.
  3. HttpServer::stop(), when in_pool_mode, sets the flag and awaits pool_await_state->all_done (mirroring the suspend in the pool-launch path of start()), instead of throwing.
  4. No new cohort is submitted afterward — running/in_pool_mode are cleared like the non-pool stop() already does.

Rough estimate: half a day to a day — most of the hard cross-thread coordination is already proven working by reload(); this is adapting it, not building it from scratch.

Where this was found

laravel-spawn, src/Server/TrueAsyncServer.php::registerShutdownSignals() — currently catches the exception and logs it, since there's nothing more it can do from PHP until this lands. See that PR for the workaround.

Activity

  1. self-assigned this
    on Jul 12, 2026
  2. added
    bug
    on Jul 12, 2026
  3. added theissue type on Jul 12, 2026
  4. added this to the Next2 milestone on Jul 12, 2026
  5. added a commit that references this issue on Jul 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bug

Type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions