worker: fix potential race in post action

Signed-off-by: Robin Jarry <robin@jarry.cc>
This commit is contained in:
Robin Jarry
2024-12-29 17:21:53 +01:00
parent 14eef02ecc
commit 1ec34824d3

View File

@@ -106,14 +106,13 @@ func (worker *Worker) processQueue() {
// from the same goroutine that the worker runs in or deadlocks may occur
func (worker *Worker) PostAction(msg WorkerMessage, cb func(msg WorkerMessage)) {
worker.setId(msg)
// write to actions channel without blocking
worker.queue(msg)
if cb != nil {
worker.Lock()
worker.actionCallbacks[msg.getId()] = cb
worker.Unlock()
}
// write to actions channel without blocking
worker.queue(msg)
}
var WorkerMessages = make(chan WorkerMessage, 50)