@@ -260,7 +260,7 @@ func (o *Orchestrator) Build(req *protocol.BuildRequest, resp protocol.ImageBuil
260
260
BaseRef : req .BaseImageNameResolved ,
261
261
})
262
262
if err != nil {
263
- return err
263
+ return handleFailedBuildStreamResponse ( err , "cannot send build response" )
264
264
}
265
265
return nil
266
266
}
@@ -307,7 +307,7 @@ func (o *Orchestrator) Build(req *protocol.BuildRequest, resp protocol.ImageBuil
307
307
BaseRef : baseref ,
308
308
})
309
309
if err != nil {
310
- return err
310
+ return handleFailedBuildStreamResponse ( err , "cannot send build response" )
311
311
}
312
312
return nil
313
313
}
@@ -322,7 +322,7 @@ func (o *Orchestrator) Build(req *protocol.BuildRequest, resp protocol.ImageBuil
322
322
323
323
randomUUID , err := uuid .NewRandom ()
324
324
if err != nil {
325
- return
325
+ return status . Errorf ( codes . Internal , "failed to generate build ID: %v" , err )
326
326
}
327
327
328
328
var (
@@ -368,7 +368,7 @@ func (o *Orchestrator) Build(req *protocol.BuildRequest, resp protocol.ImageBuil
368
368
369
369
pbaseref , err := reference .ParseNormalizedNamed (baseref )
370
370
if err != nil {
371
- return xerrors .Errorf ("cannot parse baseref: %v" , err )
371
+ return status .Errorf (codes . InvalidArgument , "cannot parse baseref: %v" , err )
372
372
}
373
373
bobBaseref := "localhost:8080/base"
374
374
if r , ok := pbaseref .(reference.Digested ); ok {
@@ -384,7 +384,7 @@ func (o *Orchestrator) Build(req *protocol.BuildRequest, resp protocol.ImageBuil
384
384
})
385
385
additionalAuth , err = json .Marshal (ath )
386
386
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 )
388
388
}
389
389
}
390
390
@@ -476,8 +476,8 @@ func (o *Orchestrator) Build(req *protocol.BuildRequest, resp protocol.ImageBuil
476
476
477
477
err := resp .Send (update )
478
478
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" )
481
481
}
482
482
483
483
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
555
555
556
556
err := resp .Send (update )
557
557
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" )
560
560
}
561
561
}
562
562
@@ -709,6 +709,20 @@ func (o *Orchestrator) getWorkspaceImageRef(ctx context.Context, baseref string)
709
709
return fmt .Sprintf ("%s:%x" , o .Config .WorkspaceImageRepository , dst ), nil
710
710
}
711
711
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
+ log .WithError (err ).WithField ("code" , status .Code (err )).Error (fmt .Sprintf ("unexpected error while sending build response: %s" , msg ))
718
+
719
+ if _ , ok := status .FromError (err ); err != nil && ok {
720
+ return err
721
+ }
722
+
723
+ return status .Errorf (codes .Unavailable , "%s: %v" , msg , err )
724
+ }
725
+
712
726
// parentCantCancelContext is a bit of a hack. We have some operations which we want to keep alive even after clients
713
727
// disconnect. gRPC cancels the context once a client disconnects, thus we intercept the cancelation and act as if
714
728
// nothing had happened.
0 commit comments