Fix a deadlock in acquiring vehicle from coordinator
Some checks failed
Some checks failed
This commit is contained in:
parent
4756ac8f32
commit
3b1d615239
1 changed files with 7 additions and 2 deletions
|
|
@ -65,12 +65,17 @@ func (c *Coordinator) Delete(vehicle api.Vehicle) {
|
|||
|
||||
func (c *Coordinator) acquire(owner loadpoint.API, vehicle api.Vehicle) {
|
||||
c.mu.Lock()
|
||||
defer c.mu.Unlock()
|
||||
|
||||
if o, ok := c.tracked[vehicle]; ok && o != owner {
|
||||
o.SetVehicle(nil)
|
||||
// defer call to SetVehicle to avoid deadlock on c.mu
|
||||
defer func(o loadpoint.API) {
|
||||
o.SetVehicle(nil)
|
||||
}(o)
|
||||
}
|
||||
c.tracked[vehicle] = owner
|
||||
|
||||
// unlock before deferred SetVehicle executes a this will round-trip back here
|
||||
c.mu.Unlock()
|
||||
}
|
||||
|
||||
func (c *Coordinator) release(vehicle api.Vehicle) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue