Fix deadlock when calling runtime.close().
This CL re-jiggers some Locks, and miraculously fixes the deadlock that
I was seeing on runtime.close.
I no longer have to call Finish on the ipc call when I get the remote
blessings.
Change-Id: Id009015c2204cfe03592f123b7054757edb8812e
diff --git a/services/wsprd/app/app.go b/services/wsprd/app/app.go
index 92e436f..46eaa71 100644
--- a/services/wsprd/app/app.go
+++ b/services/wsprd/app/app.go
@@ -261,7 +261,6 @@
func (c *Controller) Cleanup() {
vlog.VI(0).Info("Cleaning up controller")
c.Lock()
- defer c.Unlock()
for _, request := range c.outstandingRequests {
if request.cancel != nil {
@@ -272,7 +271,15 @@
}
}
+ servers := []*server.Server{}
for _, server := range c.servers {
+ servers = append(servers, server)
+ }
+
+ c.Unlock()
+
+ // We must unlock before calling server.Stop otherwise it can deadlock.
+ for _, server := range servers {
server.Stop()
}
@@ -727,13 +734,6 @@
return nil, err
}
- // TODO(nlacasse): This call.Finish() should not be necessary, since
- // cancelling the context should cause the call to end. However, for
- // some reason, if we don't call Finish(), the server.Stop() hangs
- // during cleanup. (Although it does not hang if we do server.Stop()
- // before cleanup.)
- call.Finish()
-
blessings, _ := call.RemoteBlessings()
return blessings, nil
}
diff --git a/services/wsprd/browspr/browspr.go b/services/wsprd/browspr/browspr.go
index 9fbb1a7..db88c62 100644
--- a/services/wsprd/browspr/browspr.go
+++ b/services/wsprd/browspr/browspr.go
@@ -92,16 +92,19 @@
}
b.mu.Lock()
+
if instance, ok := b.activeInstances[msg.InstanceId]; ok {
- delete(b.activeInstances, msg.InstanceId)
// We must unlock the mutex before calling cleanunp, otherwise
// browspr deadlocks.
b.mu.Unlock()
instance.cleanup()
- } else {
- b.mu.Unlock()
+
+ b.mu.Lock()
+ delete(b.activeInstances, msg.InstanceId)
}
+ b.mu.Unlock()
+
return nil, nil
}