From 0d17d8f4215b0fddf58878de98845fdebd1ded87 Mon Sep 17 00:00:00 2001 From: DarthSim Date: Fri, 29 Aug 2025 21:19:55 +0300 Subject: [PATCH] asyncbuffer: set io.ErrUnexpectedEOF before indicating that we finished reading --- asyncbuffer/buffer.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/asyncbuffer/buffer.go b/asyncbuffer/buffer.go index f9b3d139..9976dd3e 100644 --- a/asyncbuffer/buffer.go +++ b/asyncbuffer/buffer.go @@ -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() }()