limit log vertex size with 1M to avoid huge grpc message making client buffer overflow

Signed-off-by: sunchunming <sunchunming1@jd.com>
master
sunchunming 2021-11-10 15:09:25 +08:00
parent a87b801ca0
commit bb24010f6e
2 changed files with 12 additions and 2 deletions

View File

@ -333,8 +333,8 @@ func (c *Controller) Status(req *controlapi.StatusRequest, stream controlapi.Con
return nil return nil
} }
logSize := 0 logSize := 0
retry := false
for { for {
retry := false
sr := controlapi.StatusResponse{} sr := controlapi.StatusResponse{}
for _, v := range ss.Vertexes { for _, v := range ss.Vertexes {
sr.Vertexes = append(sr.Vertexes, &controlapi.Vertex{ sr.Vertexes = append(sr.Vertexes, &controlapi.Vertex{
@ -366,7 +366,7 @@ func (c *Controller) Status(req *controlapi.StatusRequest, stream controlapi.Con
Msg: v.Data, Msg: v.Data,
Timestamp: v.Timestamp, Timestamp: v.Timestamp,
}) })
logSize += len(v.Data) logSize += len(v.Data) + emptyLogVertexSize
// avoid logs growing big and split apart if they do // avoid logs growing big and split apart if they do
if logSize > 1024*1024 { if logSize > 1024*1024 {
ss.Vertexes = nil ss.Vertexes = nil

10
control/init.go Normal file
View File

@ -0,0 +1,10 @@
package control
import controlapi "github.com/moby/buildkit/api/services/control"
var emptyLogVertexSize int
func init() {
emptyLogVertex := controlapi.VertexLog{}
emptyLogVertexSize = emptyLogVertex.Size()
}