Skip to content

Commit

Permalink
Wait to finish reading logs before calling Wait() on pipeline (woodpe…
Browse files Browse the repository at this point in the history
…cker-ci#1010)

This fixes errors like the following and chopped off logs ...
  • Loading branch information
thestr4ng3r authored Jul 31, 2022
1 parent 5557674 commit 7031904
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions pipeline/pipeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package pipeline
import (
"context"
"strings"
"sync"
"time"

"github.com/rs/zerolog"
Expand Down Expand Up @@ -216,13 +217,16 @@ func (r *Runtime) exec(step *backend.Step) (*backend.State, error) {
return nil, err
}

var wg sync.WaitGroup
if r.logger != nil {
rc, err := r.engine.Tail(r.ctx, step)
if err != nil {
return nil, err
}

wg.Add(1)
go func() {
defer wg.Done()
logger := r.MakeLogger()

if err := r.logger.Log(step, multipart.New(rc)); err != nil {
Expand All @@ -237,6 +241,9 @@ func (r *Runtime) exec(step *backend.Step) (*backend.State, error) {
return nil, nil
}

// Some pipeline backends, such as local, will close the pipe from Tail on Wait,
// so first make sure all reading has finished.
wg.Wait()
waitState, err := r.engine.Wait(r.ctx, step)
if err != nil {
return nil, err
Expand Down

0 comments on commit 7031904

Please sign in to comment.