Merge pull request #2020 from kinvolk/alban/fix-getWalkedProcPid

procspy: use a Reader to copy the background reader buffer
This commit is contained in:
Alfonso Acosta
2016-12-07 12:53:53 +01:00
committed by GitHub

View File

@@ -46,7 +46,10 @@ func (br *backgroundReader) getWalkedProcPid(buf *bytes.Buffer) (map[uint64]*Pro
br.mtx.Lock()
defer br.mtx.Unlock()
_, err := io.Copy(buf, br.latestBuf)
// Don't access latestBuf directly but create a reader. In this way,
// the buffer will not be empty in the next call of getWalkedProcPid
// and it can be copied again.
_, err := io.Copy(buf, bytes.NewReader(br.latestBuf.Bytes()))
return br.latestSockets, err
}