You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It turns out that if you have a pgzip.Reader which has read to the end of the
stream, if you call io.Copy on that stream you get io.EOF -- which should
never happen and causes spurious errors on callers that check error values from io.Copy. I hit this when working on opencontainers/umoci#360.
This happens because (as an optimisation) io.Copy will use the WriteTo
method of the reader (or ReadFrom method of the writer) if they support that
method. And in this mode, io.Copy simply returns whatever error the reader or
writer give it -- meaning it doesn't hide io.EOFs returned from those
methods. In the normal Read+Write mode, io.Copy does hide the error.
It seems as though this is at some level a stdlib bug, because this requirement
of io.WriterTo and io.ReaderTo implementations (don't return io.EOF
because io.Copy can't handle it) is not spelled out anywhere in the
documentation. So either io.Copy should handle this, or this requirment
should be documented. So I will open a parallel issue on the Go tracker for
this problem.
But for now, it seems that the WriteTo implementation should avoid returning io.EOF. If the reader reaches an io.EOF before it is expected, the error
should instead be io.ErrUnexpectedEOF.
The text was updated successfully, but these errors were encountered:
Here's a simple reproducer -- note that in this case, Read is called until the end of the stream is reached and then WriteTo is called. https://play.golang.org/p/touWFY2ATjv
It turns out that if you have a
pgzip.Reader
which has read to the end of thestream, if you call
io.Copy
on that stream you getio.EOF
-- which shouldnever happen and causes spurious errors on callers that check error values from
io.Copy
. I hit this when working on opencontainers/umoci#360.This happens because (as an optimisation)
io.Copy
will use theWriteTo
method of the reader (or
ReadFrom
method of the writer) if they support thatmethod. And in this mode,
io.Copy
simply returns whatever error the reader orwriter give it -- meaning it doesn't hide
io.EOF
s returned from thosemethods. In the normal
Read
+Write
mode,io.Copy
does hide the error.It seems as though this is at some level a stdlib bug, because this requirement
of
io.WriterTo
andio.ReaderTo
implementations (don't returnio.EOF
because
io.Copy
can't handle it) is not spelled out anywhere in thedocumentation. So either
io.Copy
should handle this, or this requirmentshould be documented. So I will open a parallel issue on the Go tracker for
this problem.
But for now, it seems that the
WriteTo
implementation should avoid returningio.EOF
. If the reader reaches anio.EOF
before it is expected, the errorshould instead be
io.ErrUnexpectedEOF
.The text was updated successfully, but these errors were encountered: