Skip to content

Commit

Permalink
finish the leave process if broadcasting leave timeout (#640)
Browse files Browse the repository at this point in the history
* finish the leave process if broadcasting leave timeout

* Log broadcast timeout as WARN and finish the Leave process.

* increase timeout
  • Loading branch information
dhiaayachi committed Jan 12, 2022
1 parent d223c69 commit daf7d4f
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion serf/coalesce_member_test.go
Expand Up @@ -134,7 +134,7 @@ func TestMemberEventCoalesce_TagUpdate(t *testing.T) {
Members: []Member{Member{Name: "foo", Tags: map[string]string{"role": "foo"}}},
}

time.Sleep(10 * time.Millisecond)
time.Sleep(30 * time.Millisecond)

select {
case e := <-outCh:
Expand Down
6 changes: 3 additions & 3 deletions serf/serf.go
Expand Up @@ -4,7 +4,6 @@ import (
"bytes"
"encoding/base64"
"encoding/json"
"errors"
"fmt"
"io/ioutil"
"log"
Expand Down Expand Up @@ -685,6 +684,7 @@ func (s *Serf) broadcastJoin(ltime LamportTime) error {

// Leave gracefully exits the cluster. It is safe to call this multiple
// times.
// If the Leave broadcast timeout, Leave() will try to finish the sequence as best effort.
func (s *Serf) Leave() error {
// Check the current state
s.stateLock.Lock()
Expand Down Expand Up @@ -727,14 +727,14 @@ func (s *Serf) Leave() error {
select {
case <-notifyCh:
case <-time.After(s.config.BroadcastTimeout):
return errors.New("timeout while waiting for graceful leave")
s.logger.Printf("[WARN] serf: timeout while waiting for graceful leave")
}
}

// Attempt the memberlist leave
err := s.memberlist.Leave(s.config.BroadcastTimeout)
if err != nil {
return err
s.logger.Printf("[WARN] serf: timeout waiting for leave broadcast: %s", err.Error())
}

// Wait for the leave to propagate through the cluster. The broadcast
Expand Down

0 comments on commit daf7d4f

Please sign in to comment.