File tree Expand file tree Collapse file tree 2 files changed +12
-15
lines changed
Expand file tree Collapse file tree 2 files changed +12
-15
lines changed Original file line number Diff line number Diff line change @@ -93,9 +93,7 @@ func New(params *models.HAParams) *Service {
9393
9494// Run runs the high availability service.
9595func (s * Service ) Run (ctx context.Context ) error {
96- s .wg .Add (1 )
97- go func () {
98- defer s .wg .Done ()
96+ s .wg .Go (func () {
9997 for {
10098 select {
10199 case <- s .services .Refresh ():
@@ -107,7 +105,7 @@ func (s *Service) Run(ctx context.Context) error {
107105 return
108106 }
109107 }
110- }( )
108+ })
111109
112110 if ! s .params .Enabled {
113111 s .l .Infoln ("High availability is disabled" )
Original file line number Diff line number Diff line change @@ -50,7 +50,7 @@ func (s *services) Add(service LeaderService) error {
5050
5151 id := service .ID ()
5252 if _ , ok := s .all [id ]; ok {
53- return fmt .Errorf ("service with id %s is already exist " , id )
53+ return fmt .Errorf ("service with id %s already exists " , id )
5454 }
5555 s .all [id ] = service
5656 select {
@@ -66,16 +66,17 @@ func (s *services) StartAllServices(ctx context.Context) {
6666
6767 for id , service := range s .all {
6868 if _ , ok := s .running [id ]; ! ok {
69- s .wg .Add (1 )
7069 s .running [id ] = service
71- go func (svc LeaderService , svcID string ) {
72- s .l .Infoln ("Starting" , svcID )
73- err := svc .Start (ctx )
74- if err != nil {
75- s .l .Errorln (err )
76- s .removeService (svcID )
70+ s .wg .Go (func (svc LeaderService , svcID string ) func () {
71+ return func () {
72+ s .l .Infoln ("Starting" , svcID )
73+ err := svc .Start (ctx )
74+ if err != nil {
75+ s .l .Errorln (err )
76+ s .removeService (svcID )
77+ }
7778 }
78- }(service , id )
79+ }(service , id ))
7980 }
8081 }
8182}
@@ -88,7 +89,6 @@ func (s *services) StopRunningServices() {
8889 s .l .Infoln ("Stopping" , service .ID ())
8990 service .Stop ()
9091 delete (s .running , id )
91- s .wg .Done ()
9292 }
9393}
9494
@@ -104,5 +104,4 @@ func (s *services) removeService(id string) {
104104 s .rw .Lock ()
105105 defer s .rw .Unlock ()
106106 delete (s .running , id )
107- s .wg .Done ()
108107}
You can’t perform that action at this time.
0 commit comments