Skip to content

fix: stop persisting routes service in worker mode (hostname/subdomain route options) - #10808

Open
gr8man wants to merge 2 commits into
codeigniter4:developfrom
gr8man:fix/worker-hostname-routes
Open

gr8man wants to merge 2 commits into
codeigniter4:developfrom
gr8man:fix/worker-hostname-routes

Conversation

@gr8man

@gr8man gr8man commented Nov 20, 2026

Copy link
Copy Markdown
Contributor

Description

In Worker Mode, RouteCollection decides route registration while it loads the route definitions: it reads the request host once (system/Router/RouteCollection.php:285) and drops the routes limited with the hostname or subdomain options that do not match the current request (:1347-1361). Because the shipped Config\WorkerMode::$persistentServices kept the routes service alive across requests, those decisions were made once, from the first request the worker served, and kept for the lifetime of the process: a host-restricted route became reachable from any Host, and a route that lost the first decision stayed unreachable until the worker restarted.

This removes routes from the default $persistentServices, so the route definitions are loaded for each request and the host is evaluated per request - identical to traditional PHP.

Design note: the deeper fix - enforcing the host at route-match time, the way filters work - cannot land in a patch release: route storage is keyed by URI path only, so the documented same-URI-on-two-hosts case would collide. That redesign belongs to a minor release. The accepted cost of this change is that the routes file is re-read per request - a small, documented amount of work compared with what Worker Mode already eliminates.

Tests and docs: a regression test asserts the shipped default no longer persists routes (it fails without the change). Updated: the user guide (docs/installation/worker_mode.md), an upgrading note for existing installations (docs/installation/upgrade_477.md, "Worker Mode Routes Are Reloaded Per Request", plus the project-file content change entry), and one changelog line under "Bugs Fixed". The worker entry-point template needs no change. Full CI matrix left to GitHub Actions.

Note for reviewers: this flips a documented default on the patch line (removing routes from $persistentServices in project space). It is shipped as a correctness fix for the hostname/subdomain route options in Worker Mode, with changelog and upgrading entries; maintainer confirmation of the default change is requested. Existing installations keep the old default until they merge the updated file.

Checklist:

  • Securely signed commits
  • Component(s) with PHPDoc blocks, only if necessary or adds value (the WorkerMode docblock now documents why routes is not persistent)
  • Unit testing, with >80% coverage (regression test that fails without the change)
  • User guide updated (docs/installation/worker_mode.md; upgrading note in docs/installation/upgrade_477.md)
  • Conforms to style guide (file-scoped checks)

@carson-codeigniter4 carson-codeigniter4 Bot added the bug Verified issues on the current code behavior or pull requests that will fix them label Nov 20, 2026
@gr8man
gr8man force-pushed the fix/worker-hostname-routes branch from a03f94e to 367870d Compare November 20, 2026 23:22

@michalsn michalsn left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch!

Comment thread app/Config/WorkerMode.php Resolved
Comment thread docs/installation/upgrade_477.md Resolved
Comment thread docs/installation/worker_mode.md Resolved
Comment thread docs/installation/worker_mode.md Resolved
Comment thread docs/installation/upgrade_477.md Resolved
- Remove the duplicated routes explanation from the Config\WorkerMode::$persistentServices docblock.
- Drop the Behavior Changes section from the 4.7.7 upgrade guide.
- Shorten the Config bullet and link it to Persistent Services instead.
- Move the route reload bullet after the request state reset and drop an unmeasured cost claim in worker_mode.md.
- Retarget the 4.7.7 changelog Worker Mode link to Persistent Services.
@gr8man
gr8man requested a review from michalsn November 22, 2026 21:08

@michalsn michalsn left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Please rebase.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Verified issues on the current code behavior or pull requests that will fix them

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants