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

Return a better error when join fails #124

Merged
merged 1 commit into from
Jun 22, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
27 changes: 27 additions & 0 deletions net.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ const (
encryptMsg
nackRespMsg
hasCrcMsg
errMsg
)

// compressionType is used to specify the compression algorithm
Expand Down Expand Up @@ -105,6 +106,11 @@ type nackResp struct {
SeqNo uint32
}

// err response is sent to relay the error from the remote end
type errResp struct {
Error string
}

// suspect is broadcast when we suspect a node is dead
type suspect struct {
Incarnation uint32
Expand Down Expand Up @@ -209,6 +215,19 @@ func (m *Memberlist) handleConn(conn net.Conn) {
if err != nil {
if err != io.EOF {
m.logger.Printf("[ERR] memberlist: failed to receive: %s %s", err, LogConn(conn))

resp := errResp{err.Error()}
out, err := encode(errMsg, &resp)
if err != nil {
m.logger.Printf("[ERR] memberlist: Failed to encode error response: %s", err)
return
}

err = m.rawSendMsgStream(conn, out.Bytes())
if err != nil {
m.logger.Printf("[ERR] memberlist: Failed to send error: %s %s", err, LogConn(conn))
return
}
}
return
}
Expand Down Expand Up @@ -726,6 +745,14 @@ func (m *Memberlist) sendAndReceiveState(addr string, join bool) ([]pushNodeStat
return nil, nil, err
}

if msgType == errMsg {
var resp errResp
if err := dec.Decode(&resp); err != nil {
return nil, nil, err
}
return nil, nil, fmt.Errorf("remote error: %v", resp.Error)
}

// Quit if not push/pull
if msgType != pushPullMsg {
err := fmt.Errorf("received invalid msgType (%d), expected pushPullMsg (%d) %s", msgType, pushPullMsg, LogConn(conn))
Expand Down
27 changes: 27 additions & 0 deletions net_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -785,3 +785,30 @@ func TestIngestPacket_CRC(t *testing.T) {
t.Fatalf("bad: %s", logs.String())
}
}

func TestGossip_MismatchedKeys(t *testing.T) {
c1 := testConfig()
c2 := testConfig()

// Create two agents with different gossip keys
c1.SecretKey = []byte("4W6DGn2VQVqDEceOdmuRTQ==")
c2.SecretKey = []byte("XhX/w702/JKKK7/7OtM9Ww==")

m1, err := Create(c1)
if err != nil {
t.Fatalf("err: %s", err)
}
defer m1.Shutdown()

m2, err := Create(c2)
if err != nil {
t.Fatalf("err: %s", err)
}
defer m2.Shutdown()

// Make sure we get this error on the joining side
_, err = m2.Join([]string{c1.BindAddr})
if err == nil || !strings.Contains(err.Error(), "No installed keys could decrypt the message") {
t.Fatalf("bad: %s", err)
}
}