worker: do not lock while callbacks are running
Commit716ade8968
("worker: lock access to callback maps") introduced locks to the worker callback maps. The locks also locked the processing of the callback, which had the unintended side effect of deadlocking the worker if any callbacks attempted to post a new action or message. Refactor the locks to only lock the worker while accessing the maps. Fixes:716ade8968
("worker: lock access to callback maps") Signed-off-by: Tim Culverhouse <tim@timculverhouse.com> Acked-by: Robin Jarry <robin@jarry.cc>
This commit is contained in:
parent
7701f22bf0
commit
ea58e76332
1 changed files with 10 additions and 4 deletions
|
@ -87,13 +87,16 @@ func (worker *Worker) ProcessMessage(msg WorkerMessage) WorkerMessage {
|
||||||
}
|
}
|
||||||
if inResponseTo := msg.InResponseTo(); inResponseTo != nil {
|
if inResponseTo := msg.InResponseTo(); inResponseTo != nil {
|
||||||
worker.Lock()
|
worker.Lock()
|
||||||
if f, ok := worker.actionCallbacks[inResponseTo.getId()]; ok {
|
f, ok := worker.actionCallbacks[inResponseTo.getId()]
|
||||||
|
worker.Unlock()
|
||||||
|
if ok {
|
||||||
f(msg)
|
f(msg)
|
||||||
if _, ok := msg.(*Done); ok {
|
if _, ok := msg.(*Done); ok {
|
||||||
|
worker.Lock()
|
||||||
delete(worker.actionCallbacks, inResponseTo.getId())
|
delete(worker.actionCallbacks, inResponseTo.getId())
|
||||||
|
worker.Unlock()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
worker.Unlock()
|
|
||||||
}
|
}
|
||||||
return msg
|
return msg
|
||||||
}
|
}
|
||||||
|
@ -106,13 +109,16 @@ func (worker *Worker) ProcessAction(msg WorkerMessage) WorkerMessage {
|
||||||
}
|
}
|
||||||
if inResponseTo := msg.InResponseTo(); inResponseTo != nil {
|
if inResponseTo := msg.InResponseTo(); inResponseTo != nil {
|
||||||
worker.Lock()
|
worker.Lock()
|
||||||
if f, ok := worker.messageCallbacks[inResponseTo.getId()]; ok {
|
f, ok := worker.messageCallbacks[inResponseTo.getId()]
|
||||||
|
worker.Unlock()
|
||||||
|
if ok {
|
||||||
f(msg)
|
f(msg)
|
||||||
if _, ok := msg.(*Done); ok {
|
if _, ok := msg.(*Done); ok {
|
||||||
|
worker.Lock()
|
||||||
delete(worker.messageCallbacks, inResponseTo.getId())
|
delete(worker.messageCallbacks, inResponseTo.getId())
|
||||||
|
worker.Unlock()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
worker.Unlock()
|
|
||||||
}
|
}
|
||||||
return msg
|
return msg
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue