Skip to content

Commit

Permalink
Ensure build is not destroyed until streaming returns
Browse files Browse the repository at this point in the history
  • Loading branch information
cognifloyd committed Nov 18, 2022
1 parent eb66fb7 commit e882fd1
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions cmd/vela-worker/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package main

import (
"context"
"sync"
"time"

"github.com/go-vela/worker/executor"
Expand Down Expand Up @@ -109,7 +110,13 @@ func (w *Worker) exec(index int) error {
timeoutCtx, timeout := context.WithTimeout(buildCtx, t)
defer timeout()

// This WaitGroup delays calling DestroyBuild until the StreamBuild goroutine finishes.
var wg sync.WaitGroup

defer func() {
// if exec() exits before starting StreamBuild, this returns immediately.
wg.Wait()

logger.Info("destroying build")

// destroy the build with the executor (pass a background
Expand Down Expand Up @@ -139,7 +146,9 @@ func (w *Worker) exec(index int) error {
}

// log/event streaming uses buildCtx so that it is not subject to the timeout.
wg.Add(1)
go func() {
defer wg.Done()
logger.Info("streaming build logs")
// execute the build with the executor
err = _executor.StreamBuild(buildCtx)
Expand Down

0 comments on commit e882fd1

Please sign in to comment.