Explorar o código

Merge pull request #1533 from aboch/ag

Allow concurrent calls to agentClose
Jana Radhakrishnan %!s(int64=8) %!d(string=hai) anos
pai
achega
6ffe3a2b3d
Modificáronse 1 ficheiros con 11 adicións e 7 borrados
  1. 11 7
      libnetwork/agent.go

+ 11 - 7
libnetwork/agent.go

@@ -328,22 +328,26 @@ func (c *controller) agentDriverNotify(d driverapi.Driver) {
 }
 
 func (c *controller) agentClose() {
-	if c.agent == nil {
+	// Acquire current agent instance and reset its pointer
+	// then run closing functions
+	c.Lock()
+	agent := c.agent
+	c.agent = nil
+	c.Unlock()
+
+	if agent == nil {
 		return
 	}
 
-	for _, cancelFuncs := range c.agent.driverCancelFuncs {
+	for _, cancelFuncs := range agent.driverCancelFuncs {
 		for _, cancel := range cancelFuncs {
 			cancel()
 		}
 	}
-	c.agent.epTblCancel()
 
-	c.agent.networkDB.Close()
+	agent.epTblCancel()
 
-	c.Lock()
-	c.agent = nil
-	c.Unlock()
+	agent.networkDB.Close()
 }
 
 func (n *network) isClusterEligible() bool {