File tree Expand file tree Collapse file tree 1 file changed +4
-4
lines changed Expand file tree Collapse file tree 1 file changed +4
-4
lines changed Original file line number Diff line number Diff line change @@ -54,19 +54,20 @@ type keepAliveServer struct {
54
54
func (s keepAliveServer ) Start (fn RegisterFn ) error {
55
55
errCh := make (chan error )
56
56
stopCh := make (chan struct {})
57
- ctx , cancel := context .WithTimeout (context .Background (), time .Minute )
58
- defer cancel ()
57
+ defer close (stopCh )
59
58
60
59
go func () {
61
60
defer close (errCh )
62
61
select {
63
- case <- ctx .Done ():
64
62
case errCh <- s .Server .Start (fn ):
65
63
case <- stopCh :
64
+ // prevent goroutine leak
66
65
}
67
66
}()
68
67
69
68
// Wait for the service to start successfully, otherwise the registration service will fail.
69
+ ctx , cancel := context .WithTimeout (context .Background (), time .Minute )
70
+ defer cancel ()
70
71
ticker := time .NewTicker (time .Second )
71
72
72
73
l:
76
77
if health .IsReady () {
77
78
err := s .registerEtcd ()
78
79
if err != nil {
79
- close (stopCh )
80
80
return err
81
81
}
82
82
// break for loop
You can’t perform that action at this time.
0 commit comments