diff --git a/pkg/build/strategies/sti/sti.go b/pkg/build/strategies/sti/sti.go index ba5b1eda3..7c0c30ecd 100644 --- a/pkg/build/strategies/sti/sti.go +++ b/pkg/build/strategies/sti/sti.go @@ -560,7 +560,6 @@ func (builder *STI) Execute(command string, user string, config *api.Config) err }() opts.Stdin = r - defer wg.Wait() } go func(reader io.Reader) { @@ -591,16 +590,17 @@ func (builder *STI) Execute(command string, user string, config *api.Config) err go dockerpkg.StreamContainerIO(errReader, &errOutput, func(a ...interface{}) { glog.Info(a...) }) err := builder.docker.RunContainer(opts) - if util.IsTimeoutError(err) { - // Cancel waiting for source input if the container timeouts - wg.Done() - } if e, ok := err.(errors.ContainerError); ok { // even with deferred close above, close errReader now so we avoid data race condition on errOutput; // closing will cause StreamContainerIO to exit, thus releasing the writer in the equation errReader.Close() return errors.NewContainerError(config.BuilderImage, e.ErrorCode, errOutput) } + // Do not wait for source input if the container times out. + // FIXME: this potentially leaks a goroutine. + if !util.IsTimeoutError(err) { + wg.Wait() + } return err }