From fe44217dc4a20f644c99ff2df65b45fda8b753eb Mon Sep 17 00:00:00 2001 From: luke-lombardi <33990301+luke-lombardi@users.noreply.github.com> Date: Fri, 5 Apr 2024 18:43:01 -0400 Subject: [PATCH] fix logs race condition in worker (#124) Co-authored-by: Luke Lombardi --- internal/worker/worker.go | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/internal/worker/worker.go b/internal/worker/worker.go index 72362d983..5d91a7e07 100644 --- a/internal/worker/worker.go +++ b/internal/worker/worker.go @@ -256,14 +256,9 @@ func (s *Worker) RunContainer(request *types.ContainerRequest) error { bundlePath := filepath.Join(s.userImagePath, request.ImageId) - hostname := fmt.Sprintf("%s:%d", s.podAddr, defaultWorkerServerPort) - err := s.containerRepo.SetWorkerAddress(request.ContainerId, hostname) - if err != nil { - return err - } - + // Pull image log.Printf("<%s> - lazy-pulling image: %s\n", containerID, request.ImageId) - err = s.imageClient.PullLazy(request.ImageId) + err := s.imageClient.PullLazy(request.ImageId) if err != nil && request.SourceImage != nil { log.Printf("<%s> - lazy-pull failed, pulling source image: %s\n", containerID, *request.SourceImage) err = s.imageClient.PullAndArchiveImage(context.TODO(), *request.SourceImage, request.ImageId, nil) @@ -501,6 +496,10 @@ func (s *Worker) spawn(request *types.ContainerRequest, bundlePath string, spec } s.containerInstances.Set(containerId, containerInstance) + // Set worker hostname + hostname := fmt.Sprintf("%s:%d", s.podAddr, defaultWorkerServerPort) + s.containerRepo.SetWorkerAddress(request.ContainerId, hostname) + // Handle stdout/stderr from spawned container go s.containerLogger.CaptureLogs(request.ContainerId, outputChan)