Repository navigation
Conversation
- add Factories::resetExcept() to selectively clear factory components - add Factories::resetForWorkerMode() preserving persistent factories - add $persistentFactories property to Config\WorkerMode (default: ['config']) - update frankenphp-worker.php.tpl to call Factories::resetForWorkerMode($workerConfig) - update Worker Mode documentation, upgrading guide, and changelog - add unit tests covering selective reset, worker mode persistence, and state isolation
michalsn
left a comment
There was a problem hiding this comment.
This can leak configuration between requests. Config properties are mutable, and Registrars may return request-specific values. In Worker Mode, a later request could receive a config instance initialized for a previous client, without running its Registrar again. Our existing warning against Config Caching in Worker Mode reflects this risk. File Locator Caching is also disabled because of stale data concerns.
|
Thank you for pointing this out. You are completely right — I overlooked that I am closing this PR. Thank you for the thorough review and explanation! |
Description
In FrankenPHP Worker Mode,
Factories::reset()was executed after every request, destroying all shared instances includingConfig\*objects (Config\App,Config\Database,Config\Security, etc.). This forced each subsequent request in the worker lifecycle to rediscover, re-instantiate, and re-parse environment variables for stateless configuration classes.This PR introduces selective factory retention:
Factories::resetExcept(array $components): voidto selectively reset factories while preserving specified components.Factories::resetForWorkerMode(?WorkerMode $config = null): voidto reset factories between requests while retaining persistent components configured in$persistentFactories.$persistentFactoriesproperty toConfig\WorkerMode(defaulting to['config']).frankenphp-worker.php.tplto callFactories::resetForWorkerMode($workerConfig).Checklist: