From f286ba3d36269faeb26f8129208f6c77c0430318 Mon Sep 17 00:00:00 2001 From: Marten Seemann Date: Wed, 18 Jan 2017 10:22:04 +0700 Subject: [PATCH] fix error code when there are no common version in version negotiation --- client.go | 13 ++++++++++--- client_test.go | 4 ++-- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/client.go b/client.go index 788aa123a..f41f2e473 100644 --- a/client.go +++ b/client.go @@ -38,7 +38,6 @@ var errHostname = errors.New("Invalid hostname") var ( errCloseSessionForNewVersion = errors.New("closing session in order to recreate it with a new version") - errInvalidVersionNegotiation = qerr.Error(qerr.InvalidVersionNegotiationPacket, "Server already supports client's version and should have accepted the connection.") ) // NewClient makes a new client @@ -153,11 +152,19 @@ func (c *Client) handlePacket(packet []byte) error { } if hdr.VersionFlag { - // check if the server sent the offered version in supported versions + var hasCommonVersion bool // check if we're supporting any of the offered versions for _, v := range hdr.SupportedVersions { + // check if the server sent the offered version in supported versions if v == c.version { - return errInvalidVersionNegotiation + return qerr.Error(qerr.InvalidVersionNegotiationPacket, "Server already supports client's version and should have accepted the connection.") } + if v != protocol.VersionUnsupported { + hasCommonVersion = true + } + } + if !hasCommonVersion { + utils.Infof("No common version found.") + return qerr.InvalidVersion } ok, highestSupportedVersion := protocol.HighestSupportedVersion(hdr.SupportedVersions) diff --git a/client_test.go b/client_test.go index 9e790431d..e088ff8b7 100644 --- a/client_test.go +++ b/client_test.go @@ -228,7 +228,7 @@ var _ = Describe("Client", func() { It("errors if no matching version is found", func() { err := client.handlePacket(getVersionNegotiation([]protocol.VersionNumber{1})) - Expect(err).To(MatchError(qerr.VersionNegotiationMismatch)) + Expect(err).To(MatchError(qerr.InvalidVersion)) }) It("ignores delayed version negotiation packets", func() { @@ -244,7 +244,7 @@ var _ = Describe("Client", func() { It("errors if the server should have accepted the offered version", func() { err := client.handlePacket(getVersionNegotiation([]protocol.VersionNumber{client.version})) - Expect(err).To(MatchError(errInvalidVersionNegotiation)) + Expect(err).To(MatchError(qerr.Error(qerr.InvalidVersionNegotiationPacket, "Server already supports client's version and should have accepted the connection."))) }) }) })