From 543f3d5bdcaa5ac6e3a6b1904f69b788b5c42b51 Mon Sep 17 00:00:00 2001 From: Alban Crequy Date: Fri, 18 Nov 2016 16:23:13 +0100 Subject: [PATCH] procspy: use a Reader to copy the background reader buffer getWalkedProcPid() reads latestBuf every 3 seconds (for each report). But performWalk() writes latestBuf every 10 seconds or so. So we need to be able to read the same buffer several times. --- probe/endpoint/procspy/background_reader_linux.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/probe/endpoint/procspy/background_reader_linux.go b/probe/endpoint/procspy/background_reader_linux.go index ce4ee2a4f..d618998a6 100644 --- a/probe/endpoint/procspy/background_reader_linux.go +++ b/probe/endpoint/procspy/background_reader_linux.go @@ -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 }