Skip to content

Commit af100cb

Browse files
committed
x
1 parent 97d1f96 commit af100cb

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

zrpc/internal/rpcpubserver.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,19 +54,20 @@ type keepAliveServer struct {
5454
func (s keepAliveServer) Start(fn RegisterFn) error {
5555
errCh := make(chan error)
5656
stopCh := make(chan struct{})
57-
ctx, cancel := context.WithTimeout(context.Background(), time.Minute)
58-
defer cancel()
57+
defer close(stopCh)
5958

6059
go func() {
6160
defer close(errCh)
6261
select {
63-
case <-ctx.Done():
6462
case errCh <- s.Server.Start(fn):
6563
case <-stopCh:
64+
// prevent goroutine leak
6665
}
6766
}()
6867

6968
// 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()
7071
ticker := time.NewTicker(time.Second)
7172

7273
l:
@@ -76,7 +77,6 @@ l:
7677
if health.IsReady() {
7778
err := s.registerEtcd()
7879
if err != nil {
79-
close(stopCh)
8080
return err
8181
}
8282
// break for loop

0 commit comments

Comments
 (0)