Skip to content

Commit b092e5e

Browse files
committed
Do not set beta protocol flag when using v5
Driver was automatically setting beta flag when using v5 protocol which causes issues when trying to connect to Cassandra versions that supported beta v5 like 3.11. Patch by João Reis; reviewed by TBD for CASSGO-88
1 parent a6e8291 commit b092e5e

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

control.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,10 +204,17 @@ func shuffleHosts(hosts []*HostInfo) []*HostInfo {
204204

205205
// this is going to be version dependant and a nightmare to maintain :(
206206
var protocolSupportRe = regexp.MustCompile(`the lowest supported version is \d+ and the greatest is (\d+)$`)
207+
var betaProtocolRe = regexp.MustCompile(`Beta version of the protocol used \(.*\), but USE_BETA flag is unset`)
207208

208209
func parseProtocolFromError(err error) int {
210+
errStr := err.Error()
211+
209212
// I really wish this had the actual info in the error frame...
210-
matches := protocolSupportRe.FindAllStringSubmatch(err.Error(), -1)
213+
matches := betaProtocolRe.FindAllStringSubmatch(errStr, -1)
214+
if len(matches) == 1 {
215+
return int(highestProtocolVersionSupported - 1)
216+
}
217+
matches = protocolSupportRe.FindAllStringSubmatch(errStr, -1)
211218
if len(matches) != 1 || len(matches[0]) != 2 {
212219
if verr, ok := err.(*protocolError); ok {
213220
return int(verr.frame.Header().version.version())
@@ -223,11 +230,13 @@ func parseProtocolFromError(err error) int {
223230
return max
224231
}
225232

233+
const highestProtocolVersionSupported = 5
234+
226235
func (c *controlConn) discoverProtocol(hosts []*HostInfo) (int, error) {
227236
hosts = shuffleHosts(hosts)
228237

229238
connCfg := *c.session.connCfg
230-
connCfg.ProtoVersion = 5 // TODO: define maxProtocol
239+
connCfg.ProtoVersion = highestProtocolVersionSupported
231240

232241
handler := connErrorHandlerFn(func(c *Conn, err error, closed bool) {
233242
// we should never get here, but if we do it means we connected to a

frame.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -393,9 +393,6 @@ func newFramer(compressor Compressor, version byte, r *RegisteredTypes) *framer
393393
if compressor != nil {
394394
flags |= flagCompress
395395
}
396-
if version == protoVersion5 {
397-
flags |= flagBetaProtocol
398-
}
399396

400397
version &= protoVersionMask
401398

0 commit comments

Comments
 (0)