Skip to content

Resolve request scoped head state from the current container - #17

Open
MrFallen wants to merge 1 commit into
laravel:mainfrom
MrFallen:fix-request-state-current-container
Open

MrFallen wants to merge 1 commit into
laravel:mainfrom
MrFallen:fix-request-state-current-container

Conversation

@MrFallen

Copy link
Copy Markdown

HeadManager is a singleton, but it resolves the request scoped CurrentHead (as well as SsrState and the request) from the container it was constructed with.

Under Octane the application is booted once per worker and cloned for every request. HeadManager is usually resolved while booting (any Head::defaults() call in a service provider does that), so it keeps a reference to the worker's base container, and CurrentHead is resolved into the base container instead of the request's clone:

  • normally Octane forgets the base container's scoped instances when the request terminates, so this goes unnoticed;
  • when a request ends with an exception that escapes the kernel, Octane reports it but does not dispatch RequestTerminated, and the next request on that worker starts with the previous request's title, description, canonical and the rest of its head data.

This PR resolves the request scoped state from Container::getInstance(), which Octane swaps for every request (the approach the Octane docs recommend for singletons that need the container). In a regular application the current container is the application itself, so nothing changes there. A test simulates two cloned request containers and asserts that the head data of the first one doesn't reach the second.

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.

1 participant