From 49296e321e18c4c8db54f7d6d0d13c9ce39de2fb Mon Sep 17 00:00:00 2001 From: Tristan Colgate Date: Thu, 25 Jul 2019 13:14:02 +0100 Subject: [PATCH] Event queue processes and filling race. We send the slice off to be process, but potentially start overwriting the previous content straight away. Just start again with a fresh slice. Fixes #247 Signed-off-by: Tristan Colgate --- event.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/event.go b/event.go index 258b923..8c9cc50 100644 --- a/event.go +++ b/event.go @@ -82,6 +82,7 @@ func newEventQueue(c chan Events, flushThreshold int, flushInterval time.Duratio c: c, flushThreshold: flushThreshold, flushTicker: ticker, + q: make([]Event, 0, flushThreshold), } go func() { for { @@ -112,7 +113,7 @@ func (eq *eventQueue) flush() { func (eq *eventQueue) flushUnlocked() { eq.c <- eq.q - eq.q = eq.q[:0] + eq.q = make([]Event, 0, cap(eq.q)) eventsFlushed.Inc() }