aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTim Culverhouse <tim@timculverhouse.com>2022-09-16 14:41:06 -0500
committerRobin Jarry <robin@jarry.cc>2022-09-20 00:03:36 +0200
commit74735711595c3f0dc29177f767b2c91beef19617 (patch)
tree65e6301e5c3f8283914a71e4af8e9241ffe8adef
parentf4d6ade429850aa30b5f6a8aefc3ef5a00c2e584 (diff)
downloadaerc-74735711595c3f0dc29177f767b2c91beef19617.tar.gz
worker: prevent deadlock by flooding worker.Messages channel
Send to worker.Messages in goroutine to prevent deadlocks: the UI can fill the worker.Actions channel. The worker can generate more than one Message per action, and if it generates enough to fill the worker.Messages channel from a single message while the worker.Actions channel is full, a deadlock occurs. Signed-off-by: Tim Culverhouse <tim@timculverhouse.com> Acked-by: Robin Jarry <robin@jarry.cc>
-rw-r--r--worker/types/worker.go5
1 files changed, 4 insertions, 1 deletions
diff --git a/worker/types/worker.go b/worker/types/worker.go
index ba396aa3..5a964f2f 100644
--- a/worker/types/worker.go
+++ b/worker/types/worker.go
@@ -64,7 +64,10 @@ func (worker *Worker) PostMessage(msg WorkerMessage,
} else {
logging.Debugf("PostMessage %T", msg)
}
- worker.Messages <- msg
+ // This one needs to be in a separate goroutine to prevent deadlocks
+ go func() {
+ worker.Messages <- msg
+ }()
if cb != nil {
worker.messageCallbacks[msg.getId()] = cb