File tree Expand file tree Collapse file tree 1 file changed +14
-7
lines changed Expand file tree Collapse file tree 1 file changed +14
-7
lines changed Original file line number Diff line number Diff line change @@ -52,15 +52,21 @@ type keepAliveServer struct {
5252}
5353
5454func (s keepAliveServer ) Start (fn RegisterFn ) error {
55- chErr := make (chan error )
55+ errCh := make (chan error )
56+ stopCh := make (chan struct {})
57+ ctx , cancel := context .WithTimeout (context .Background (), time .Minute )
58+ defer cancel ()
59+
5660 go func () {
57- defer close (chErr )
58- chErr <- s .Server .Start (fn )
61+ defer close (errCh )
62+ select {
63+ case <- ctx .Done ():
64+ case errCh <- s .Server .Start (fn ):
65+ case <- stopCh :
66+ }
5967 }()
6068
6169 // Wait for the service to start successfully, otherwise the registration service will fail.
62- ctx , cancel := context .WithTimeout (context .Background (), time .Minute )
63- defer cancel ()
6470 ticker := time .NewTicker (time .Second )
6571
6672l:
7076 if health .IsReady () {
7177 err := s .registerEtcd ()
7278 if err != nil {
79+ close (stopCh )
7380 return err
7481 }
7582 // break for loop
7683 break l
7784 }
7885 case <- ctx .Done ():
7986 return errNotReady
80- case err := <- chErr :
87+ case err := <- errCh :
8188 return err
8289 }
8390 }
8491 ticker .Stop ()
8592
86- return <- chErr
93+ return <- errCh
8794}
8895
8996func figureOutListenOn (listenOn string ) string {
You can’t perform that action at this time.
0 commit comments