Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

agent: add 1 buffer to errc to prevent goroutine leak #11302

Closed
wants to merge 1 commit into from

Conversation

lzhfromustc
Copy link
Contributor

Description
In function (*Server).runEtcd(), if select at line 150 chooses case <-time.After(time.Minute):, then the goroutine created at line 125 will be blocked forever, because there is no receive to synchronize with errc <- srv.startProxy() at line 129

func (srv *Server) runEtcd() error {
errc := make(chan error)
go func() {
time.Sleep(5 * time.Second)
// server advertise client/peer listener had to start first
// before setting up proxy listener
errc <- srv.startProxy()
}()
if srv.etcdCmd != nil {
srv.lg.Info(
"starting etcd command",
zap.String("command-path", srv.etcdCmd.Path),
)
err := srv.etcdCmd.Start()
perr := <-errc
srv.lg.Info(
"started etcd command",
zap.String("command-path", srv.etcdCmd.Path),
zap.Errors("errors", []error{err, perr}),
)
if err != nil {
return err
}
return perr
}
select {
case <-srv.etcdServer.Server.ReadyNotify():
srv.lg.Info("embedded etcd is ready")
case <-time.After(time.Minute):
srv.etcdServer.Close()
return fmt.Errorf("took too long to start %v", <-srv.etcdServer.Err())
}
return <-errc
}

How it is fixed
This patch is similar to line 210 in file lease/leasehttp/http.go of #7015
We add 1 buffer to the channel errc, and then the send errc <- srv.startProxy() will not be blocked and no goroutine will be leaked, but all receives will still be waiting for sent. So this patch is very safe.

@codecov-io
Copy link

Codecov Report

Merging #11302 into master will increase coverage by 0.29%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##           master   #11302      +/-   ##
==========================================
+ Coverage   64.05%   64.35%   +0.29%     
==========================================
  Files         403      403              
  Lines       37953    37953              
==========================================
+ Hits        24312    24424     +112     
+ Misses      11980    11888      -92     
+ Partials     1661     1641      -20
Impacted Files Coverage Δ
pkg/netutil/netutil.go 63.11% <0%> (-6.56%) ⬇️
pkg/logutil/zap_grpc.go 47.61% <0%> (-4.77%) ⬇️
clientv3/retry_interceptor.go 65% <0%> (-4.5%) ⬇️
clientv3/leasing/util.go 95% <0%> (-3.34%) ⬇️
auth/store.go 65.9% <0%> (-2.43%) ⬇️
etcdserver/api/v3rpc/lease.go 67.04% <0%> (-2.28%) ⬇️
clientv3/op.go 72.08% <0%> (-1.25%) ⬇️
embed/serve.go 36.48% <0%> (-0.91%) ⬇️
etcdserver/cluster_util.go 56.52% <0%> (-0.8%) ⬇️
clientv3/leasing/cache.go 87.22% <0%> (-0.56%) ⬇️
... and 20 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 84e2788...083f767. Read the comment docs.

Copy link
Member

@spzala spzala left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm thanks!

@stale
Copy link

stale bot commented May 20, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed after 21 days if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label May 20, 2020
@stale stale bot closed this Jun 10, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

Successfully merging this pull request may close these issues.

3 participants