-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
session: fix grpc message size limits for tar streams #4313
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -47,6 +47,22 @@ type streamWriterCloser struct { | |
} | ||
|
||
func (wc *streamWriterCloser) Write(dt []byte) (int, error) { | ||
// grpc-go has a 4MB limit on messages by default. Split large messages | ||
// so we don't get close to that limit. | ||
const maxChunkSize = 3 * 1024 * 1024 | ||
if len(dt) > maxChunkSize { | ||
n1, err := wc.Write(dt[:maxChunkSize]) | ||
if err != nil { | ||
return n1, err | ||
} | ||
dt = dt[maxChunkSize:] | ||
var n2 int | ||
if n2, err = wc.Write(dt); err != nil { | ||
return n1 + n2, err | ||
} | ||
return n1 + n2, nil | ||
Comment on lines
+60
to
+63
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: could we change this recursion into a loop? If we get an error deep in the stack if we have very large messages, the stack will be pretty unreadable. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Realistically, I would never expect to get too big messages in here. The limit is 16MB anyway so anything bigger than 5x would already start to fail on these conditions. |
||
} | ||
|
||
if err := wc.ClientStream.SendMsg(&BytesMessage{Data: dt}); err != nil { | ||
// SendMsg return EOF on remote errors | ||
if errors.Is(err, io.EOF) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a note - this logic feels very similar to what's already implemented in
fsutil.Send
with a buffer pool. I wonder if (as a follow-up) we could push the logic to send/receive single files into fsutil (which could let us re-use the same limiting logic, so if we want to update the size of the messages we send, we don't have to do it everywhere).