fix: handle calling Contents on massive files #6772
Merged
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.
Fixes #6743.
We have a message size limit enforced by the gRPC connection - however, we then go to host a HTTP server on that connection, and we weren't performing any restrictions on the size of the
Write
s.To resolve this, for any
Write
that is larger than (an adjusted for headers) size limit, we split it into multipleWrite
calls which will split it into severalBytesMessage
s by thegrpchijack
package.Note: no such transformation is required for
Read
s, since go permits short-reads, but does not permit short-writes (sogrpchijack
can return under the requested number of bytes).Arguably, this should be implemented upstream, however, it's tricky. Currently, the only upstream use of
grpchijack
is to host the session, which performs it's own message shortening procedures, which seems very fair - this patch just creates our own similar generic implementation for HTTP serving.