Open matejvasek opened 3 years ago
logging.PrefixWriter which is not
io.Closer
so everything works all right.
correction: logging.PrefixWriter
actually is io.Closer
but it doesn't really close the underlying io.Writer
that it is wrapping
this was probably introduced in https://github.com/buildpacks/pack/pull/867
cc @jromero
@matejvasek are you still seeing this issue?
Summary
I am using
pack
code as a library in my own Go project. I am not sure how much is this supported and whether this is really a bug.Still:
The issue is that after invocation of
packClient.Build()
thelogWriter
is closed.There is a code that check whether
logWriter
instance also implementsio.Closer
and if it does it will call close on it deliberately. In case that the builder is trusted thelogWriter
(os.Stdout
) is unaltered passed down and closed (since it is*os.File
). This is not good, especially forstdout
.In case the builder is not trusted the
logWriter
is wrapped bylogging.PrefixWriter
which is notio.Closer
so everything works all right.In standalone
pack
CLI it's not an issue because theos.Stdout
is closed just before exiting, but if used a an library this is not convenient.For now I workarounded this by wrapping
os.Stdout
into a struct that implements onlyio.Writer
notio.Closer
.IMHO the
io.Writer
passed to the API shouldn't be closed, it's really surprising when that happens.It might make sense if the parameter had to be
io.WriteCloser
, then user could expect that the stream will be closed.