Skip to content

Commit

Permalink
pkg/eventqueue: fix concurrent access of waitConsumeOffQueue
Browse files Browse the repository at this point in the history
spanStart of waitConsumeOffQueue could be read before being written in
case the buffered event was executed before the execution of
waitConsumeOffQueue.Start() in the modified lines of this commit. To fix
this we should execute waitConsumeOffQueue.Start() even before the event
is put into the queue. Although it does not give the correct span stat,
the developer or user can derive it by subtracting the waitEnqueue span
to retrieve the real waitConsumeOffQueue span.

Fixes: add0d65 ("add eventqueue package")
Signed-off-by: André Martins <andre@cilium.io>
  • Loading branch information
aanm committed Feb 12, 2020
1 parent 4b61dd5 commit da2e652
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions pkg/eventqueue/eventqueue.go
Expand Up @@ -144,7 +144,7 @@ type eventStatistics struct {
durationStat spanstat.SpanStat

// waitConsumeOffQueue shows how long it took for the event to be consumed
// off of the queue.
// plus the time it the event waited in the queue.
waitConsumeOffQueue spanstat.SpanStat
}

Expand Down Expand Up @@ -213,9 +213,9 @@ func (q *EventQueue) Enqueue(ev *Event) (<-chan interface{}, error) {
// event is processed, then it will be cancelled.

ev.stats.waitEnqueue.Start()
ev.stats.waitConsumeOffQueue.Start()
q.events <- ev
ev.stats.waitEnqueue.End(true)
ev.stats.waitConsumeOffQueue.Start()
return ev.eventResults, nil
}
}
Expand Down

0 comments on commit da2e652

Please sign in to comment.