Skip to content

Commit

Permalink
uploadprovider: avoid too big grpc messages on tar upload
Browse files Browse the repository at this point in the history
Signed-off-by: Tonis Tiigi <[email protected]>
  • Loading branch information
tonistiigi committed Oct 10, 2023
1 parent ac33aec commit 463bdab
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions session/upload/uploadprovider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,20 @@ type writer struct {
}

func (w *writer) Write(dt []byte) (int, error) {
// avoid sending too big messages on grpc stream
const maxChunkSize = 3 * 1024 * 1024
if len(dt) > maxChunkSize {
n1, err := w.Write(dt[:maxChunkSize])
if err != nil {
return n1, err
}
dt = dt[maxChunkSize:]
var n2 int
if n2, err := w.Write(dt); err != nil {
return n1 + n2, err
}
return n1 + n2, nil
}
if err := w.SendMsg(&upload.BytesMessage{Data: dt}); err != nil {
return 0, err
}
Expand Down

0 comments on commit 463bdab

Please sign in to comment.