Improving EncoderStream to return error only upon non io.EOF.

io.EOF is okay since io.ReadFull will not have read any bytes at all.

Also making error channel receive only for go routine.
This commit is contained in:
Harshavardhana
2015-07-25 15:50:25 -07:00
parent 4ac23d747c
commit e082f26e10
6 changed files with 12 additions and 1260 deletions
+3 -4
View File
@@ -447,14 +447,13 @@ func (b bucket) writeObjectData(k, m uint8, writers []io.WriteCloser, objectData
}
for blockIndex, block := range encodedBlocks {
errCh := make(chan error, 1)
go func(writer io.Writer, reader io.Reader) {
// FIXME: this closes the errCh in the outer scope
go func(writer io.Writer, reader io.Reader, errCh chan<- error) {
defer close(errCh)
_, err := io.Copy(writer, reader)
errCh <- err
}(writers[blockIndex], bytes.NewReader(block))
}(writers[blockIndex], bytes.NewReader(block), errCh)
if err := <-errCh; err != nil {
// FIXME: fix premature return in case of err != nil
// Returning error is fine here CleanupErrors() would cleanup writers
return 0, 0, iodine.New(err, nil)
}
}