From ad937a9f5b40e0d4526fa1107e48602b17f4bd68 Mon Sep 17 00:00:00 2001 From: Nils Wireklint Date: Wed, 7 Feb 2024 10:39:40 +0100 Subject: [PATCH] Log action errors for build directory cleanup There was no error reporting for failure to clean up the build directories and this would fail creation of the same action the next time it is executed. This is an unexpected error and we have not needed it before, but on Windows some files may be locked. We cannot return an error to the client, as it may retry the action and then fail directory creation, and keep retrying. --- pkg/builder/local_build_executor.go | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/pkg/builder/local_build_executor.go b/pkg/builder/local_build_executor.go index 847dc21c..f495392e 100644 --- a/pkg/builder/local_build_executor.go +++ b/pkg/builder/local_build_executor.go @@ -2,6 +2,7 @@ package builder import ( "context" + "log" "os" "sync" "time" @@ -127,9 +128,9 @@ func (be *localBuildExecutor) CheckReadiness(ctx context.Context) error { return err } -func (be *localBuildExecutor) Execute(ctx context.Context, filePool re_filesystem.FilePool, monitor access.UnreadDirectoryMonitor, digestFunction digest.Function, request *remoteworker.DesiredState_Executing, executionStateUpdates chan<- *remoteworker.CurrentState_Executing) *remoteexecution.ExecuteResponse { +func (be *localBuildExecutor) Execute(ctx context.Context, filePool re_filesystem.FilePool, monitor access.UnreadDirectoryMonitor, digestFunction digest.Function, request *remoteworker.DesiredState_Executing, executionStateUpdates chan<- *remoteworker.CurrentState_Executing) (response *remoteexecution.ExecuteResponse) { // Timeout handling. - response := NewDefaultExecuteResponse(request) + response = NewDefaultExecuteResponse(request) action := request.Action if action == nil { attachErrorToExecuteResponse(response, status.Error(codes.InvalidArgument, "Request does not contain an action")) @@ -160,7 +161,12 @@ func (be *localBuildExecutor) Execute(ctx context.Context, filePool re_filesyste util.StatusWrap(err, "Failed to acquire build environment")) return response } - defer buildDirectory.Close() + defer func() { + err := buildDirectory.Close() + if err != nil { + log.Printf("Failed to clean up build environment: %v\n", err) + } + }() // Install hooks on build directory to capture file creation and // I/O error events.