Selaa lähdekoodia

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

DarthSim 1 kuukausi sitten
vanhempi
commit
0d17d8f421
1 muutettua tiedostoa jossa 6 lisäystä ja 6 poistoa
  1. 6 6
      asyncbuffer/buffer.go

+ 6 - 6
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()
 	}()