Skip to content

Commit

Permalink
server, client: fix hanging problem when etcd failed to start (#1267)
Browse files Browse the repository at this point in the history
  • Loading branch information
disksing authored Oct 12, 2018
1 parent 36b88f9 commit a6b3a6c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
4 changes: 3 additions & 1 deletion client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,9 @@ func (c *client) initClusterID() error {
defer cancel()
for i := 0; i < maxInitClusterRetries; i++ {
for _, u := range c.urls {
members, err := c.getMembers(ctx, u)
timeoutCtx, timeoutCancel := context.WithTimeout(ctx, pdTimeout)
members, err := c.getMembers(timeoutCtx, u)
timeoutCancel()
if err != nil || members.GetHeader() == nil {
log.Errorf("[pd] failed to get cluster id: %v", err)
continue
Expand Down
4 changes: 4 additions & 0 deletions server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import (

const (
etcdTimeout = time.Second * 3
etcdStartTimeout = time.Minute * 5
serverMetricsInterval = time.Minute
// pdRootPath for all pd servers.
pdRootPath = "/pd"
Expand Down Expand Up @@ -134,6 +135,9 @@ func CreateServer(cfg *Config, apiRegister func(*Server) http.Handler) (*Server,

func (s *Server) startEtcd(ctx context.Context) error {
log.Info("start embed etcd")
ctx, cancel := context.WithTimeout(ctx, etcdStartTimeout)
defer cancel()

etcd, err := embed.StartEtcd(s.etcdCfg)
if err != nil {
return errors.WithStack(err)
Expand Down

0 comments on commit a6b3a6c

Please sign in to comment.