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

Remove unnecessary timeout in WaitForLeader() #3256

Merged
merged 1 commit into from
Jul 19, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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