fix: Too much data for declared Content-Length
error when endpoint caches enabled
#92
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
When using endpoint caches, for large payload sizes, the Edge Proxy would throw an exception but return a 200 OK response with an empty body. Looking in the logs, I determined the cause was
When I compared a cached response with a non-cached response, I could see that the cached response was setting a
Content-Length
header about 1/4 of the size of the non-cached response.I haven't investigated the cause of this too deeply as it seems to be buried deep in the internals of
lru_cache
and/orORJSONResponse
code. Instead, I have abstracted the serialization back to themain
module and out of the environment service which, to me, feels cleaner anyway. It adds a small amount of processing back to the response generation, even when a cache hit is made, but in testing this seems negligible.To test this fix, I attempted to write a test using the Fast API client, but I wasn't able to reproduce the error. Instead, I ran the edge proxy locally with the endpoint caches enabled and verified that multiple requests to the same endpoint, with the same data, work as expected.