@@ -260,7 +260,7 @@ func (o *Orchestrator) Build(req *protocol.BuildRequest, resp protocol.ImageBuil
260260				BaseRef : req .BaseImageNameResolved ,
261261			})
262262			if  err  !=  nil  {
263- 				return  err 
263+ 				return  handleFailedBuildStreamResponse ( err ,  "cannot send build response" ) 
264264			}
265265			return  nil 
266266		}
@@ -307,7 +307,7 @@ func (o *Orchestrator) Build(req *protocol.BuildRequest, resp protocol.ImageBuil
307307			BaseRef : baseref ,
308308		})
309309		if  err  !=  nil  {
310- 			return  err 
310+ 			return  handleFailedBuildStreamResponse ( err ,  "cannot send build response" ) 
311311		}
312312		return  nil 
313313	}
@@ -322,7 +322,7 @@ func (o *Orchestrator) Build(req *protocol.BuildRequest, resp protocol.ImageBuil
322322
323323	randomUUID , err  :=  uuid .NewRandom ()
324324	if  err  !=  nil  {
325- 		return 
325+ 		return   status . Errorf ( codes . Internal ,  "failed to generate build ID: %v" ,  err ) 
326326	}
327327
328328	var  (
@@ -368,7 +368,7 @@ func (o *Orchestrator) Build(req *protocol.BuildRequest, resp protocol.ImageBuil
368368
369369	pbaseref , err  :=  reference .ParseNormalizedNamed (baseref )
370370	if  err  !=  nil  {
371- 		return  xerrors .Errorf ("cannot parse baseref: %v" , err )
371+ 		return  status .Errorf (codes . InvalidArgument ,  "cannot parse baseref: %v" , err )
372372	}
373373	bobBaseref  :=  "localhost:8080/base" 
374374	if  r , ok  :=  pbaseref .(reference.Digested ); ok  {
@@ -384,7 +384,7 @@ func (o *Orchestrator) Build(req *protocol.BuildRequest, resp protocol.ImageBuil
384384		})
385385		additionalAuth , err  =  json .Marshal (ath )
386386		if  err  !=  nil  {
387- 			return  xerrors .Errorf ("cannot marshal additional auth: %w " , err )
387+ 			return  status .Errorf (codes . InvalidArgument ,  "cannot marshal additional auth: %v " , err )
388388		}
389389	}
390390
@@ -476,8 +476,8 @@ func (o *Orchestrator) Build(req *protocol.BuildRequest, resp protocol.ImageBuil
476476
477477		err  :=  resp .Send (update )
478478		if  err  !=  nil  {
479- 			log .WithError (err ).Error ("cannot forward build update - dropping listener" )
480- 			return  status . Errorf ( codes . Unknown , "cannot send update: %v"  ,  err )
479+ 			log .WithError (err ).Info ("cannot forward build update - dropping listener" )
480+ 			return  handleFailedBuildStreamResponse ( err , "cannot send update"  )
481481		}
482482
483483		if  update .Status  ==  protocol .BuildStatus_done_failure  ||  update .Status  ==  protocol .BuildStatus_done_success  {
@@ -555,8 +555,8 @@ func (o *Orchestrator) Logs(req *protocol.LogsRequest, resp protocol.ImageBuilde
555555
556556		err  :=  resp .Send (update )
557557		if  err  !=  nil  {
558- 			log .WithError (err ).Error ("cannot forward log output - dropping listener" )
559- 			return  status . Errorf ( codes . Unknown , "cannot send log output: %v"  ,  err )
558+ 			log .WithError (err ).Info ("cannot forward log output - dropping listener" )
559+ 			return  handleFailedBuildStreamResponse ( err , "cannot send log output"  )
560560		}
561561	}
562562
@@ -709,6 +709,20 @@ func (o *Orchestrator) getWorkspaceImageRef(ctx context.Context, baseref string)
709709	return  fmt .Sprintf ("%s:%x" , o .Config .WorkspaceImageRepository , dst ), nil 
710710}
711711
712+ func  handleFailedBuildStreamResponse (err  error , msg  string ) error  {
713+ 	if  status .Code (err ) ==  codes .DeadlineExceeded  {
714+ 		// client disconnected before we could send the response - fine with us 
715+ 		return  nil 
716+ 	}
717+ 
718+ 	if  _ , ok  :=  status .FromError (err ); err  !=  nil  &&  ok  {
719+ 		log .WithError (err ).Error (fmt .Sprintf ("gRPC status error: %s" , msg ))
720+ 		return  err 
721+ 	}
722+ 
723+ 	return  status .Errorf (codes .Unavailable , "%s: %v" , msg , err )
724+ }
725+ 
712726// parentCantCancelContext is a bit of a hack. We have some operations which we want to keep alive even after clients 
713727// disconnect. gRPC cancels the context once a client disconnects, thus we intercept the cancelation and act as if 
714728// nothing had happened. 
0 commit comments