Skip to content

Commit

Permalink
Merge pull request hashicorp#97 from abligh/dont-close-transport-twice
Browse files Browse the repository at this point in the history
Ensure we don't call the shutdown future more than once
  • Loading branch information
slackpad committed Mar 18, 2016
2 parents 3359516 + d6d1d58 commit 90c4021
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
3 changes: 3 additions & 0 deletions future.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,9 @@ type shutdownFuture struct {
}

func (s *shutdownFuture) Error() error {
if s.raft == nil {
return nil
}
for s.raft.getRoutines() > 0 {
time.Sleep(5 * time.Millisecond)
}
Expand Down
4 changes: 3 additions & 1 deletion raft.go
Original file line number Diff line number Diff line change
Expand Up @@ -412,9 +412,11 @@ func (r *Raft) Shutdown() Future {
close(r.shutdownCh)
r.shutdown = true
r.setState(Shutdown)
return &shutdownFuture{r}
}

return &shutdownFuture{r}
// avoid closing transport twice
return &shutdownFuture{nil}
}

// Snapshot is used to manually force Raft to take a snapshot.
Expand Down
5 changes: 4 additions & 1 deletion raft_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,10 @@ func TestRaft_AfterShutdown(t *testing.T) {
}

// Should be idempotent
raft.Shutdown()
if f := raft.Shutdown(); f.Error() != nil {
t.Fatalf("shutdown should be idempotent")
}

}

func TestRaft_SingleNode(t *testing.T) {
Expand Down

0 comments on commit 90c4021

Please sign in to comment.