Closed
Description
Reader should be vetted to ensure it handles 0-length reads in a sane fashion. This is inspired by comments on #13049.
A few things need to be ensured:
- The documentation on Reader discourages returning 0 from
read()
. It should certainly be allowed, but implementors should be encouraged to avoid returning 0 if possible. - The default methods on
Reader
should all behave sanely if a single call toread()
returns 0. - Less importantly, the default methods should handle a
Reader
that returns 0 forever. Practically speaking, this means that if the method employs a loop, it should also employ a counter to count how many 0-lengthread()
s there have been in a row, and if it passes some threshold (TBD, but maybe something like 1000) then it should return an error. There should also be a newIoErrorKind
defined for this case (Go uses one calledErrNoProgress
, that seems a sensible name). - Any clients of Reader in
std
and the associated libraries should also be checked to make sure they handle 0-length reads.
The simplest way to implement this may be to add another default method read_at_least()
that takes a count of how many bytes it should ensure it has read. This method can then deal with counting 0-length reads and setting the proper error, and then everything that reads in a loop can use r.read_at_least(but, 1)
so they don't have to deal with it.
Metadata
Metadata
Assignees
Labels
No labels