Skip to content

Commit

Permalink
ai/live: Fix early EOFs (#3314)
Browse files Browse the repository at this point in the history
Sometimes if the reader is slow to pull data (eg, during a retry)
and the buffer grows larger than a read then closes, the reader
may incorrectly signal EOF and return incomplete data. Don't do that.
  • Loading branch information
j0sh authored Dec 12, 2024
1 parent abd997d commit a367c90
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion media/rw.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,11 @@ func (mw *MediaWriter) MakeReader() CloneableReader {
func (mr *MediaReader) Read(p []byte) (int, error) {
data, eof := mr.source.readData(mr.readPos)
toRead := len(p)
if len(data) < toRead {
if len(data) <= toRead {
toRead = len(data)
} else {
// there is more data to read
eof = false
}

copy(p, data[:toRead])
Expand Down

0 comments on commit a367c90

Please sign in to comment.