Browse code

judge manager if locked before parsing key

Signed-off-by: allencloud <allen.sun@daocloud.io>
(cherry picked from commit 89100c162b23791b4a64d142a11014257bf61fd0)
Signed-off-by: Victor Vieux <victorvieux@gmail.com>

allencloud authored on 2016/11/21 17:33:46
Showing 1 changed files
... ...
@@ -595,6 +595,11 @@ func (c *Cluster) UnlockSwarm(req types.UnlockRequest) error {
595 595
 			return err
596 596
 		}
597 597
 	}
598
+
599
+	if c.node != nil || c.locked != true {
600
+		c.RUnlock()
601
+		return errors.New("swarm is not locked")
602
+	}
598 603
 	c.RUnlock()
599 604
 
600 605
 	key, err := encryption.ParseHumanReadableKey(req.UnlockKey)
... ...
@@ -603,11 +608,6 @@ func (c *Cluster) UnlockSwarm(req types.UnlockRequest) error {
603 603
 	}
604 604
 
605 605
 	c.Lock()
606
-	if c.node != nil || c.locked != true {
607
-		c.Unlock()
608
-		return errors.New("swarm is not locked")
609
-	}
610
-
611 606
 	config := *c.lastNodeConfig
612 607
 	config.lockKey = key
613 608
 	n, err := c.startNewNode(config)