Skip to content

Commit

Permalink
Merge pull request #3256 from cannium/remove-unnecessary-timeout
Browse files Browse the repository at this point in the history
Remove unnecessary timeout in WaitForLeader()
  • Loading branch information
otoolep committed Jul 19, 2015
2 parents bf85ad4 + c41ef86 commit 641b38f
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions meta/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ func (s *Store) init() {
// Writes the id of the node to file on success.
func (s *Store) createLocalNode() error {
// Wait for leader.
if err := s.WaitForLeader(5 * time.Second); err != nil {
if err := s.WaitForLeader(0); err != nil {
return fmt.Errorf("wait for leader: %s", err)
}

Expand Down Expand Up @@ -382,6 +382,7 @@ func (s *Store) Snapshot() error {
}

// WaitForLeader sleeps until a leader is found or a timeout occurs.
// timeout == 0 means to wait forever.
func (s *Store) WaitForLeader(timeout time.Duration) error {
if s.raft.Leader() != "" {
return nil
Expand All @@ -399,7 +400,9 @@ func (s *Store) WaitForLeader(timeout time.Duration) error {
case <-s.closing:
return errors.New("closing")
case <-timer.C:
return errors.New("timeout")
if timeout != 0 {
return errors.New("timeout")
}
case <-ticker.C:
if s.raft.Leader() != "" {
return nil
Expand Down

0 comments on commit 641b38f

Please sign in to comment.