mirror of
https://github.com/sot-tech/mochi.git
synced 2026-05-17 05:14:50 -07:00
pool: fixed synchronization/stopping of the pool
This commit is contained in:
committed by
Jimmy Zelinskie
parent
34428cf465
commit
114322ce10
@@ -79,6 +79,8 @@ func (s *httpServer) Start() {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
log.Println("HTTP server shut down cleanly")
|
||||
}
|
||||
|
||||
func (s *httpServer) Stop() {
|
||||
|
||||
@@ -20,8 +20,7 @@ type Pool struct {
|
||||
// StartPool creates a new pool of servers specified by the provided config and
|
||||
// runs them.
|
||||
func StartPool(cfgs []config.ServerConfig, tkr *tracker.Tracker) (*Pool, error) {
|
||||
var servers []Server
|
||||
var wg sync.WaitGroup
|
||||
var toReturn Pool
|
||||
|
||||
for _, cfg := range cfgs {
|
||||
srv, err := New(&cfg, tkr)
|
||||
@@ -29,19 +28,16 @@ func StartPool(cfgs []config.ServerConfig, tkr *tracker.Tracker) (*Pool, error)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
wg.Add(1)
|
||||
toReturn.wg.Add(1)
|
||||
go func(srv Server) {
|
||||
defer wg.Done()
|
||||
defer toReturn.wg.Done()
|
||||
srv.Start()
|
||||
}(srv)
|
||||
|
||||
servers = append(servers, srv)
|
||||
toReturn.servers = append(toReturn.servers, srv)
|
||||
}
|
||||
|
||||
return &Pool{
|
||||
servers: servers,
|
||||
wg: wg,
|
||||
}, nil
|
||||
return &toReturn, nil
|
||||
}
|
||||
|
||||
// Stop safely shuts down a pool of servers.
|
||||
|
||||
@@ -48,6 +48,7 @@ func constructor(srvcfg *config.ServerConfig, tkr *tracker.Tracker) (server.Serv
|
||||
theStore = &Store{
|
||||
cfg: cfg,
|
||||
tkr: tkr,
|
||||
shutdown: make(chan struct{}),
|
||||
ClientStore: cs,
|
||||
PeerStore: ps,
|
||||
IPStore: ips,
|
||||
|
||||
Reference in New Issue
Block a user