Merge pull request #4051 from hashicorp/b-alloc-stream-snap
Fix alloc watcher snapshot streaming
This commit is contained in:
commit
b88f10ed1d
|
@ -489,7 +489,7 @@ func (p *remotePrevAlloc) streamAllocDir(ctx context.Context, resp io.ReadCloser
|
|||
// Error snapshotting on the remote side, try to read
|
||||
// the message out of the file and return it.
|
||||
errBuf := make([]byte, int(hdr.Size))
|
||||
if _, err := tr.Read(errBuf); err != nil {
|
||||
if _, err := tr.Read(errBuf); err != nil && err != io.EOF {
|
||||
return fmt.Errorf("error streaming previous alloc %q for new alloc %q; failed reading error message: %v",
|
||||
p.prevAllocID, p.allocID, err)
|
||||
}
|
||||
|
@ -542,6 +542,13 @@ func (p *remotePrevAlloc) streamAllocDir(ctx context.Context, resp io.ReadCloser
|
|||
// is still alive
|
||||
for !canceled() {
|
||||
n, err := tr.Read(buf)
|
||||
if n > 0 && (err == nil || err == io.EOF) {
|
||||
if _, err := f.Write(buf[:n]); err != nil {
|
||||
f.Close()
|
||||
return fmt.Errorf("error writing to file %q: %v", f.Name(), err)
|
||||
}
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
f.Close()
|
||||
if err != io.EOF {
|
||||
|
@ -549,10 +556,6 @@ func (p *remotePrevAlloc) streamAllocDir(ctx context.Context, resp io.ReadCloser
|
|||
}
|
||||
break
|
||||
}
|
||||
if _, err := f.Write(buf[:n]); err != nil {
|
||||
f.Close()
|
||||
return fmt.Errorf("error writing to file %q: %v", f.Name(), err)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -518,7 +518,7 @@ func TestHTTP_AllocSnapshot_Atomic(t *testing.T) {
|
|||
// Found it!
|
||||
markerFound = true
|
||||
buf := make([]byte, int(header.Size))
|
||||
if _, err := r.Read(buf); err != nil {
|
||||
if _, err := r.Read(buf); err != nil && err != io.EOF {
|
||||
t.Errorf("Unexpected error reading error marker %s: %v", errorFilename, err)
|
||||
} else {
|
||||
markerContents = string(buf)
|
||||
|
|
Loading…
Reference in a new issue