@@ -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,11 +322,12 @@ 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
+ buildID := randomUUID .String ()
328
+ log := log .WithField ("buildID" , buildID )
327
329
328
330
var (
329
- buildID = randomUUID .String ()
330
331
buildBase = "false"
331
332
contextPath = "."
332
333
dockerfilePath = "Dockerfile"
@@ -368,7 +369,7 @@ func (o *Orchestrator) Build(req *protocol.BuildRequest, resp protocol.ImageBuil
368
369
369
370
pbaseref , err := reference .ParseNormalizedNamed (baseref )
370
371
if err != nil {
371
- return xerrors .Errorf ("cannot parse baseref: %v" , err )
372
+ return status .Errorf (codes . InvalidArgument , "cannot parse baseref: %v" , err )
372
373
}
373
374
bobBaseref := "localhost:8080/base"
374
375
if r , ok := pbaseref .(reference.Digested ); ok {
@@ -384,7 +385,7 @@ func (o *Orchestrator) Build(req *protocol.BuildRequest, resp protocol.ImageBuil
384
385
})
385
386
additionalAuth , err = json .Marshal (ath )
386
387
if err != nil {
387
- return xerrors .Errorf ("cannot marshal additional auth: %w " , err )
388
+ return status .Errorf (codes . InvalidArgument , "cannot marshal additional auth: %v " , err )
388
389
}
389
390
}
390
391
@@ -432,7 +433,7 @@ func (o *Orchestrator) Build(req *protocol.BuildRequest, resp protocol.ImageBuil
432
433
Name : "WORKSPACEKIT_BOBPROXY_ADDITIONALAUTH" ,
433
434
Value : string (additionalAuth ),
434
435
},
435
- {Name : "SUPERVISOR_DEBUG_ENABLE" , Value : fmt .Sprintf ("%v" , log .Log . Logger .IsLevelEnabled (logrus .DebugLevel ))},
436
+ {Name : "SUPERVISOR_DEBUG_ENABLE" , Value : fmt .Sprintf ("%v" , log .Logger .IsLevelEnabled (logrus .DebugLevel ))},
436
437
},
437
438
},
438
439
Type : wsmanapi .WorkspaceType_IMAGEBUILD ,
@@ -476,8 +477,8 @@ func (o *Orchestrator) Build(req *protocol.BuildRequest, resp protocol.ImageBuil
476
477
477
478
err := resp .Send (update )
478
479
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 )
480
+ log .WithError (err ).Info ("cannot forward build update - dropping listener" )
481
+ return handleFailedBuildStreamResponse ( err , "cannot send update" )
481
482
}
482
483
483
484
if update .Status == protocol .BuildStatus_done_failure || update .Status == protocol .BuildStatus_done_success {
@@ -555,8 +556,8 @@ func (o *Orchestrator) Logs(req *protocol.LogsRequest, resp protocol.ImageBuilde
555
556
556
557
err := resp .Send (update )
557
558
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 )
559
+ log .WithError (err ).Info ("cannot forward log output - dropping listener" )
560
+ return handleFailedBuildStreamResponse ( err , "cannot send log output" )
560
561
}
561
562
}
562
563
@@ -709,6 +710,33 @@ func (o *Orchestrator) getWorkspaceImageRef(ctx context.Context, baseref string)
709
710
return fmt .Sprintf ("%s:%x" , o .Config .WorkspaceImageRepository , dst ), nil
710
711
}
711
712
713
+ func handleFailedBuildStreamResponse (err error , msg string ) error {
714
+ if err == nil {
715
+ // OK is OK
716
+ return nil
717
+ }
718
+
719
+ // If the error is a context.DeadlineExceeded, we return nil (OK) as requested.
720
+ if errors .Is (err , context .DeadlineExceeded ) {
721
+ // Return nil (OK) for DeadlineExceeded
722
+ return nil
723
+ }
724
+
725
+ // If it's already a gRPC status error, check for DeadlineExceeded
726
+ if st , ok := status .FromError (err ); ok {
727
+ if st .Code () == codes .DeadlineExceeded {
728
+ // Return nil (OK) for DeadlineExceeded as requested
729
+ return nil
730
+ }
731
+
732
+ log .WithError (err ).WithField ("code" , status .Code (err )).Error (fmt .Sprintf ("unexpected error while sending build response: %s" , msg ))
733
+ return err
734
+ }
735
+
736
+ log .WithError (err ).Error (fmt .Sprintf ("unexpected error while sending build response: %s" , msg ))
737
+ return status .Errorf (codes .Unavailable , "%s: %v" , msg , err )
738
+ }
739
+
712
740
// parentCantCancelContext is a bit of a hack. We have some operations which we want to keep alive even after clients
713
741
// disconnect. gRPC cancels the context once a client disconnects, thus we intercept the cancelation and act as if
714
742
// nothing had happened.
0 commit comments