Skip to content

Commit

Permalink
fix: docker backend should not close 'engine.Tail' result (#1616) (#1620
Browse files Browse the repository at this point in the history
)

Backport #1616

Close #1615

The error described in
#1615 is happening
because `Tail` method of the docker backend closes the instance of
`io.ReadCloser` it returns in `defer` function. As a result anything
that try to read data returned by `Tail` method eventually will attempt
to read from closes reader and get an error:



https://github.com/woodpecker-ci/woodpecker/blob/2171212c5a31bfffc8f882716bdd503c65413eee/pipeline/backend/docker/docker.go#L229

The fix is just don't close returned reader and let the consumer of
`Tail` method do it. Good thing is that `Tail` is used only in one place
and reader is correctly closed:



https://github.com/woodpecker-ci/woodpecker/blob/2171212c5a31bfffc8f882716bdd503c65413eee/pipeline/pipeline.go#L231-L237

Example of `woodpecker exec` output using pipeline from
#1615 with the fix:

```
woodpecker exec .woodpecker.yaml
[step1:L0:0s] + echo step1
[step1:L1:0s] step1
[step2:L0:0s] + echo step2
[step2:L1:0s] step2
```

Signed-off-by: Alexander Matyushentsev <AMatyushentsev@gmail.com>
Co-authored-by: Alexander Matyushentsev <AMatyushentsev@gmail.com>
Co-authored-by: Lauris BH <lauris@nix.lv>
  • Loading branch information
3 people authored Mar 14, 2023
1 parent 648cd60 commit d07c66d
Showing 1 changed file with 0 additions and 1 deletion.
1 change: 0 additions & 1 deletion pipeline/backend/docker/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,6 @@ func (e *docker) Tail(ctx context.Context, proc *backend.Step) (io.ReadCloser, e
_, _ = stdcopy.StdCopy(wc, wc, logs)
_ = logs.Close()
_ = wc.Close()
_ = rc.Close()
}()
return rc, nil
}
Expand Down

0 comments on commit d07c66d

Please sign in to comment.