Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[HttpKernel] Fix regression where Store does not return response body correctly #37182

Merged
merged 1 commit into from Jun 11, 2020

Conversation

mpdude
Copy link
Contributor

@mpdude mpdude commented Jun 10, 2020

Q A
Branch? 3.4
Bug fix? yes
New feature? no
Deprecations? no
Tickets Fix #37174
License MIT
Doc PR

Since #36833, the Store no longer uses or trusts the X-Content-Digest header present on a response, since that may come (in the case of using CachingHttpClient) from upstream HTTP sources. Instead, the X-Content-Digest is re-computed every time a response is written by the Store.

Additionally, the Store is implemented in a way that when restoring responses, it does not actually load the response body, but just keeps the file path to the content on disk in another internal header called X-Body-File. It is up to others (HttpCache, for example) to actually load the content from there. For reasons I could not determine, the file path is also set as the response body.

When the HttpCache performs revalidations, it may happen that it wants the Store to persist a previously restored response. In that case, the Store fails to honor its own X-Body-File header. Instead, it would compute (since #36833) the X-Content-Digest, which now is a hash of the cache file path.

So, we end up with a response that still carries X-Body-File for the original, correct response. Since the HttpCache honors this value, we don't immediately notice that. But inside the Store, the request is now associated with the new (bogus) content entry.

It takes another round of looking up the content in the Store to now get a response where the X-Body-File also points to the wrong content entry.

Although I feel a bit uncomfortable with trusting headers that seemingly need to be evaluated in different classes and may come from elsewhere, my suggestion is to skip the write inside Store if X-Body-File and X-Content-Digest are both present and consistent with each other.

Additionally, a file_exists check could be added to provide additional assertions, at the cost of accessing the filesystem.

@xabbuh xabbuh added this to the 3.4 milestone Jun 10, 2020
@nicolas-grekas nicolas-grekas changed the title [HttpKernel] Fix regression caused by #36833 [HttpKernel] Fix regression where Store does not return response body correctly Jun 11, 2020
*
* A restored response does *not* load the body, but only keep the file path in a special X-Body-File
* header. For reasons (?), the file path was also used as the restored response body.
* It would be up to others (HttpCache...?) to hohor this header and actually load the response content
Copy link
Member

Choose a reason for hiding this comment

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

honor

@fabpot
Copy link
Member

fabpot commented Jun 11, 2020

Thank you @mpdude.

@fabpot fabpot merged commit 54c9054 into symfony:3.4 Jun 11, 2020
@mpdude mpdude deleted the issue-37174 branch June 11, 2020 14:51
@@ -477,19 +490,19 @@ private function persistResponse(Response $response)
* Restores a Response from the HTTP headers and body.
*
* @param array $headers An array of HTTP headers for the Response
* @param string $body The Response body
* @param string $path Path to the Response body
Copy link
Contributor

Choose a reason for hiding this comment

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

string|null

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants