From 2d79d6d847b96da22192606da07c1ad033e9c998 Mon Sep 17 00:00:00 2001 From: Harshavardhana Date: Mon, 10 May 2021 08:20:23 -0700 Subject: [PATCH] fix: do not niladic p.writers upon failure (#12255) p.writers is a verbatim value of bitrotWriter backed by a pipe() that should never be nil'ed, instead use the captured errors to skip the writes. additionally detect also short writes, and reject them as errors. --- cmd/erasure-encode.go | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/cmd/erasure-encode.go b/cmd/erasure-encode.go index ede2a6237..c6b883e83 100644 --- a/cmd/erasure-encode.go +++ b/cmd/erasure-encode.go @@ -42,13 +42,18 @@ func (p *parallelWriter) Write(ctx context.Context, blocks [][]byte) error { p.errs[i] = errDiskNotFound continue } - + if p.errs[i] != nil { + continue + } wg.Add(1) go func(i int) { defer wg.Done() - _, p.errs[i] = p.writers[i].Write(blocks[i]) - if p.errs[i] != nil { - p.writers[i] = nil + var n int + n, p.errs[i] = p.writers[i].Write(blocks[i]) + if p.errs[i] == nil { + if n != len(blocks[i]) { + p.errs[i] = io.ErrShortWrite + } } }(i) } @@ -58,12 +63,7 @@ func (p *parallelWriter) Write(ctx context.Context, blocks [][]byte) error { // CreateFile with p.writeQuorum=1 to accommodate healing of single disk. // i.e if we do no return here in such a case, reduceWriteQuorumErrs() would // return a quorum error to HealFile(). - nilCount := 0 - for _, err := range p.errs { - if err == nil { - nilCount++ - } - } + nilCount := countErrs(p.errs, nil) if nilCount >= p.writeQuorum { return nil }