@@ -486,12 +486,14 @@ func (daemon *Daemon) restore() error {
486486 // ignore errors here as this is a best effort to wait for children to be
487487 // running before we try to start the container
488488 children := daemon .children (c )
489- timeout := time .After (5 * time .Second )
489+ timeout := time .NewTimer (5 * time .Second )
490+ defer timeout .Stop ()
491+
490492 for _ , child := range children {
491493 if notifier , exists := restartContainers [child ]; exists {
492494 select {
493495 case <- notifier :
494- case <- timeout :
496+ case <- timeout . C :
495497 }
496498 }
497499 }
@@ -609,6 +611,7 @@ func (daemon *Daemon) waitForNetworks(c *container.Container) {
609611 if daemon .discoveryWatcher == nil {
610612 return
611613 }
614+
612615 // Make sure if the container has a network that requires discovery that the discovery service is available before starting
613616 for netName := range c .NetworkSettings .Networks {
614617 // If we get `ErrNoSuchNetwork` here, we can assume that it is due to discovery not being ready
@@ -617,13 +620,19 @@ func (daemon *Daemon) waitForNetworks(c *container.Container) {
617620 if _ , ok := err .(libnetwork.ErrNoSuchNetwork ); ! ok {
618621 continue
619622 }
623+
620624 // use a longish timeout here due to some slowdowns in libnetwork if the k/v store is on anything other than --net=host
621625 // FIXME: why is this slow???
626+ dur := 60 * time .Second
627+ timer := time .NewTimer (dur )
628+
622629 logrus .Debugf ("Container %s waiting for network to be ready" , c .Name )
623630 select {
624631 case <- daemon .discoveryWatcher .ReadyCh ():
625- case <- time . After ( 60 * time . Second ) :
632+ case <- timer . C :
626633 }
634+ timer .Stop ()
635+
627636 return
628637 }
629638 }
@@ -673,10 +682,14 @@ func (daemon *Daemon) DaemonLeavesCluster() {
673682 // This is called also on graceful daemon shutdown. We need to
674683 // wait, because the ingress release has to happen before the
675684 // network controller is stopped.
685+
676686 if done , err := daemon .ReleaseIngress (); err == nil {
687+ timeout := time .NewTimer (5 * time .Second )
688+ defer timeout .Stop ()
689+
677690 select {
678691 case <- done :
679- case <- time . After ( 5 * time . Second ) :
692+ case <- timeout . C :
680693 logrus .Warn ("timeout while waiting for ingress network removal" )
681694 }
682695 } else {
0 commit comments