diff options
author | Simon Ser <contact@emersion.fr> | 2019-04-27 15:56:38 +0000 |
---|---|---|
committer | Drew DeVault <sir@cmpwn.com> | 2019-04-27 14:28:26 -0400 |
commit | 9ef2a57b51601cc0e18824bbfe8026891da1a38d (patch) | |
tree | f7f5ff2ba4e467dab56af13ef6993eac8addd481 /worker/worker.go | |
parent | 2159eb876e7e04e81f65e64b1d742ad832890289 (diff) | |
download | aerc-9ef2a57b51601cc0e18824bbfe8026891da1a38d.tar.gz |
worker/types: fix Worker.Callbacks race condition
Worker.Process* functions were called in different goroutines than Worker.Post*. Protect the map with a mutex. Also make the map unexported to prevent external unprotected accesses. Worker.Process* functions used to delete items from the map. However they didn't delete the element they retrieved: callbacks[msg.InResponseTo()] was read while callbacks[msg] was deleted. I'm not sure I understand why. I tried to delete the element that was accessed - but this broke everything (UI froze at "Connecting..."). I don't believe any elements were actually removed from the map, so the new code just doesn't remove anything.
Diffstat (limited to 'worker/worker.go')
-rw-r--r-- | worker/worker.go | 7 |
1 files changed, 1 insertions, 6 deletions
diff --git a/worker/worker.go b/worker/worker.go index 959c7df..29bb560 100644 --- a/worker/worker.go +++ b/worker/worker.go @@ -15,12 +15,7 @@ func NewWorker(source string, logger *log.Logger) (*types.Worker, error) { if err != nil { return nil, err } - worker := &types.Worker{ - Actions: make(chan types.WorkerMessage, 50), - Callbacks: make(map[types.WorkerMessage]func(msg types.WorkerMessage)), - Messages: make(chan types.WorkerMessage, 50), - Logger: logger, - } + worker := types.NewWorker(logger) switch u.Scheme { case "imap": fallthrough |