global mutex on GetPorts

This commit is contained in:
Kuba Podgórski 2021-01-14 18:04:16 +01:00
parent a100a38b4a
commit 36f17eee1d
3 changed files with 12 additions and 6 deletions

View file

@ -103,9 +103,9 @@ func (e *Etcd) Close() error {
if e.heartbeatCancel != nil {
e.heartbeatCancel()
}
e.e.Server.Stop()
e.e.Close()
<-e.e.Server.StopNotify()
// e.e.Server.Stop()
// e.e.Close()
// <-e.e.Server.StopNotify()
}
return nil

View file

@ -692,9 +692,9 @@ func (s *Server) Close() error {
errc = s.cluster.close()
}
errhs = s.syncer.stopTranslationSync()
// if s.disCo != nil {
// errd = s.disCo.Close()
// }
if s.disCo != nil {
errd = s.disCo.Close()
}
if s.holder != nil {
errh = s.holder.Close()
}

View file

@ -19,6 +19,7 @@ import (
"log"
"net"
"strings"
"sync"
"syscall"
)
@ -31,7 +32,12 @@ func GetPort(wrapper func(int) error, retries int) error {
return GetPorts(f, 1, retries)
}
var mu = &sync.Mutex{}
func GetPorts(wrapper func([]int) error, requestedPorts, retries int) error {
mu.Lock()
defer mu.Unlock()
for i := 0; i < retries; i++ {
// get all requested ports
listeners := make([]net.Listener, requestedPorts)