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 9, 2023
1 parent 0f68719 commit 9ee2bb2
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions session/upload/uploadprovider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,23 @@ 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 {
var n int
var err error
n, err = w.Write(dt[:maxChunkSize])
if err != nil {
return n, err
}
dt = dt[maxChunkSize:]
if n2, err := w.Write(dt); err != nil {
return n + n2, err
} else {
n += n2
}
return n, nil
}
if err := w.SendMsg(&upload.BytesMessage{Data: dt}); err != nil {
return 0, err
}
Expand Down

0 comments on commit 9ee2bb2

Please sign in to comment.