asyncbuffer: set io.ErrUnexpectedEOF before indicating that we finished reading

This commit is contained in:
DarthSim
2025-08-29 21:19:55 +03:00
parent c6a95facbb
commit 0d17d8f421

View File

@@ -142,6 +142,12 @@ func (ab *AsyncBuffer) addChunk(chunk *byteChunk) {
// readChunks reads data from the upstream reader in background and stores them in the pool
func (ab *AsyncBuffer) readChunks() {
defer func() {
if ab.bytesRead.Load() < int64(ab.dataLen) {
// If the reader has finished reading and we have not read enough data,
// set err to io.ErrUnexpectedEOF
ab.setErr(io.ErrUnexpectedEOF)
}
// Indicate that the reader has finished reading
ab.finished.Store(true)
ab.chunkCond.Close()
@@ -151,12 +157,6 @@ func (ab *AsyncBuffer) readChunks() {
logrus.WithField("source", "asyncbuffer.AsyncBuffer.readChunks").Warningf("error closing upstream reader: %s", err)
}
if ab.bytesRead.Load() < int64(ab.dataLen) {
// If the reader has finished reading and we have not read enough data,
// set err to io.ErrUnexpectedEOF
ab.setErr(io.ErrUnexpectedEOF)
}
ab.callFinishFn()
}()